Clear Recent Apps Wipe the Apps Memory and My Receiver Stopped Working

clear Recent apps wipe the apps memory and my receiver stopped working

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).

Android system killed my service when I clear all recent app

A long running service needs the following to make it less likely to be terminated:

  1. Return START_STICKY from onStartCommand(). With this, system will re-start the service even if it has to be stopped for resources limitations.

  2. When the service is not bound to any UI component (e.g an Activity), The service must go in foreground mode by showing a foreground notification. Foreground services are less likely to be terminated by system.

  3. Set the attribute "stopWithTask"=false in corresponding <service> tag of manifest file.

Also, note that devices from some manufacturers will terminate services even with above properties due to customization:

  1. Custom task managers.
  2. Battery saving features that can prohibit non-system services.

Some application services do need to stay in background and have to be aggressively kept alive. Though this method is not recommended, but following steps can be done:

  1. Add triggers for service start : Such as Boot Complete, and Network Connected broadcasts.

  2. If service receives intents/broadcasts FLAG_RECEIVER_FOREGROUND in the intent.

  3. An extreme resort is to manually schedule a pending intent for service restart, with AlarmManager, when onTaskRemoved() is called.

Also, see:

  1. START_STICKY does not work on Android KitKat

Broadcast receiver not working when app is cleared from RAM

In Xiaomi devices, you just have to add your app to Autostart list, to do so, follow these simple steps given below:

  • Open Security app on your phone.

  • Tap on Permissions, it'll show you two options: Autostart and
    Permissions

  • Tap on Autostart, it'll show you list of apps with on or off toggle
    buttons.

  • Turn on toggle of your app, you're done!

Broadcast receiver is not working only when app is closed in android pie

After spending few days I found the real issue.

My code was working fine on Android O and Android P both in foreground and background but when I clear the app from the recent apps list, it stops working on some devices because of

Manufacturers have added task manager feature by default which force stops the apps for memory/battery management. But few applications like Whatsapp, Facebook works. This can be because they would have whitelisted the most famous applications.

For more information follow the below link

clear Recent apps wipe the apps memory and my receiver stopped working



Related Topics



Leave a reply



Submit