简体   繁体   中英

How to keep android process alive

How does the apps like Swiftkey, Locker Master manages to keep process alive even after it has been removed from back stack?

They also don't use sticky notification.

Update:- I need to keep my process alive. But in my case service is active but process gets killed.

They all have one or more unbound background service .

To kill those services you can go into Settings -> Apps -> Running.

However the services may be restarted at any time by other apps or system by sending a system wide message (intent). In most cases it is restarted by

  • Time events
  • Boot complete
  • Other apps
  • Other intents

In the Swiftkey case, it will be started by Android OS when it needs to show a keyboard.

EDIT: you can specify that a service runs in a remote process by adding this to the service definition in AndroidManifest

android:process="process_name_here"

However there is no such thing as a service that cannot be killed and can run forever. Android OS may start killing your service if it is running low on resources or the service is running for a long period of time. To overcome this, you can make a forground running service, but it needs to show a notification. It can also be killed by task managers, like you mentioned. You should instead start focusing on how to save it's state so you are able to restart it later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM