清除最近的应用程序擦除应用程序内存,我的接收器停止工作 [英] clear Recent apps wipe the apps memory and my receiver stopped working

查看:356
本文介绍了清除最近的应用程序擦除应用程序内存,我的接收器停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  MyApp的Receiver在工作正常的情况下工作正常:public class MySmsReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context,Intent intent){
System.out.println(triggered sms);
if(intent.getAction()。equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)){
Toast.makeText(context,message Received,Toast.LENGHT_SHORT).show();
}
}

和接收者的清单文件

 < receiver android:name =。MySmsReceiver> 
< intent-filter>



我想出了一些应用程序就像watsapp和fb一直在内存中一样,在清除最近的应用程序之后仍然说任务管理器具有如下所示的followig状态,然后说这个bcoz:



< img src =https://i.stack.imgur.com/Z7VOL.jpgalt =在taskmanager中的watsapp状态>

如何能我这样做到我的应用程序..什么会让我的应用程序像watspp和Facebook等其他第三方应用程序的行为...我如何让我的应用程序在内存中总是我问这个只有M y接收器将永远工作..如果我错了,然后给我一个解决方案来做到这一点...



我一直在寻找这个很多,但我仍然找不到解决方案...我问错了吗?或者真的有办法做到这一点?请有人帮助我......这让我一周!希望我在这里解释了我的问题,如果我不问我,我会给你立即回复。

解决方案

在某些华为设备上以及一些LG和小米设备),您需要将您的应用添加到允许在后台运行的应用列表中。如果你不这样做,那么一旦你的应用程序停止了(通过从最近的任务列表中滑动,或者出于资源原因通过Android查杀应用程序),它将不会自动重新启动。



在华为设备上,该设置被称为受保护的应用程序。您无法以编程方式将您的应用添加到受保护的应用列表中。你需要告诉用户,他必须在你安装你的应用程序后才能做到这一点。众所周知的应用程序(如WhatsApp,Facebook,Google Mail)会被制造商自动添加。



这种行为在不同的设备上可能会有所不同, Android的版本,如果该设备是为特定的移动运营商标记的话,它可能会有所不同,因为移动运营商也可以自行修改设置。



a href =https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it>受保护的应用程序设置在华为手机上,以及如何处理它一些更多细节。



编辑:添加了这个:



此外,Android在Android 4.4(Kitkat)中打破了从最近收到的邮件行为,因此导致已刷卡的应用程序出现问题。粘滞服务不会延迟,并且不会传送 Intent s。这里有一些关于解决方法的信息:在android 4.4中,从最近的任务中刷出应用程序将永久性地杀死应用程序。任何想法为什么?



另外,您是否从Google Play商店安装了您的应用程序?对于已从Play商店安装的应用程序与本地安装的应用程序(从下载或通过 adb 或其他),应用程序的行为可能不同。


MyApp's Receiver is just working fine if it in background which is:

    public class MySmsReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("triggered sms");
        if(intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
          Toast.makeText(context, "message Received", Toast.LENGHT_SHORT).show();
    }
}

and my manifest file for receiver is

        <receiver android:name=".MySmsReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />

        </intent-filter>
    </receiver>

Document says that if i declare a receiver in manifest file it should always work. but in my case it's not...

But whenever I clear my recent apps by swiping them it just stopped working. and after i went to taskmanager and saw that MyApps forcestop being disabled like below

and i figured it out some apps like watsapp and fb always kept in memory am saying this bcoz after the swiping of clear recent apps still the task manager has the followig state like below

and

How can i do this into my app.. what will made my app to behave like other thirdparty apps like watspp and facebook...how can i make my app to be in memory always I am asking this Then only My receiver will always work.. If i am wrong then give me a solution to do this...

I Have been searching this a lot and still i cannot find the solution... Am i asking wrong? or really is there a way to do it? Please someone help me... This making me a week!!! Hope i explained my problem here if i am not ask me I'll give you immediate response.

解决方案

On some Huawei devices (and some LG and Xiaomi devices) you need to add your app to the list of apps that are allowed to run in the background. If you don't, once your app is stopped (by swiping from the recent tasks list, or by Android killing the app for resource reasons), it will NOT be automatically restarted.

On Huawei devices, the setting is called "protected apps". You cannot programmatically add your app to the list of "protected apps". You need to tell the user that he has to do it after you've installed your app. Well-known apps (like Whatsapp, Facebook, Google Mail) are automatically added by the manufacturer.

This behaviour may be different on different devices and it may be different on different versions of Android and it may be different if the device is "branded" for a specific mobile operator, as the mobile operators can also tinker with the settings themselves.

See "Protected Apps" setting on Huawei phones, and how to handle it for some more details.

EDIT: Added this:

Also, Android broke the "swipe from recents" behaviour in Android 4.4 (Kitkat) so that it causes problems for apps that have been swiped. Sticky services don't get retarted and broadcast Intents are not delivered. There is some information here about workarounds to deal with that: In android 4.4, swiping app out of recent tasks permanently kills application with its service . Any idea why?

Also, have you installed your app from the Google Play store? It is possible that the behaviour is different for apps that have been installed from the Play store versus apps that are locally installed (from downloads or via adb or whatever).

这篇关于清除最近的应用程序擦除应用程序内存,我的接收器停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆