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 Intent
s 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:
Return
START_STICKY
fromonStartCommand()
. With this, system will re-start the service even if it has to be stopped for resources limitations.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.
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:
- Custom task managers.
- 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:
Add triggers for service start : Such as Boot Complete, and Network Connected broadcasts.
If service receives intents/broadcasts
FLAG_RECEIVER_FOREGROUND
in the intent.An extreme resort is to manually schedule a pending intent for service restart, with
AlarmManager
, whenonTaskRemoved()
is called.
Also, see:
- 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
PermissionsTap 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
Pagination Not Work for the Recyclerview Within Nestedscrollview
How to Create a File on Android Internal Storage
Proguard with Ormlite on Android
Continuous Speech Recognition Android
Sync Scrolling of Multiple Recyclerviews
Touch and Drag Image in Android
How to Set Alarm in Android Programmatically
How to Save Images into Database
Android Listview Row Delete Animation
Suppress/Block Broadcastreceiver in Another App
Displaying Images from a Specific Folder on the Sdcard Using a Gridview
Android: Fragments Overlapping Issue
Android Volley to Handle Redirect
Android: Notifydatasetchanged(); Not Working
Downloading/Caching Google Maps for Offline Use
Forgot Keystore Password, Thinking of Brute-Force Detection. Will It Corrupt the Keystore