How to keep a service running in background even after user quits the app? [closed]

你。 提交于 2019-11-27 09:00:47
EGHDK

Right from developer.android.com

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it. A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.

So, as long as you create a service, and the user exits your app it will still run. Just like the example above.

This should give you all the information you need: https://developer.android.com/guide/components/services.html

you can use Alarm manager for any background service.

For particular timing you want to perform something which can be service.

And for the continues process,You can start service from alarm manager.

One of the android suggested way :

A started service can use the startForeground(int, Notification). API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory. (It is still theoretically possible for the service to be killed under extreme memory pressure from the current foreground application, but in practice this should not be a concern.)

Other way is restart the service when its stopped (System will call onDestroy() on service which is stopped)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!