简体   繁体   中英

How to make service running even after manually swiping off of recent apps?

I am trying to build a count down timer that runs in the background in a separate thread. I am using a foreground service and passing a handler to the background thread from this service. So essentially, the activity will communicate with the service and the service will communicate with the thread.

Essentially, when the user swipes the app off from the recent apps, i need the timer to keep running.

What is the best design that does this?

You will need to use a started Service and startForeground() .

Check this question for details.

Also if you create service in a separate process it will solve your issue.

Here is a great tutorial

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.

Like Ivan previously said, it is a combination of startService(), binding calls and startForeground() call to keep the service running in the background. Don't really require a separate process to do this.

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