简体   繁体   中英

How to make service running even if there is no activity running?

Is there any way to keep my background service running indefinitely even if there is no activity of application currently running ?

there is a requirement where user can use other application on the phone and he either closed all application's activities or he moved to other application so the activity of my application goes to pause or stop state so in this case service should not get destroy.

I am not sure how to make it possible because as of now what I observed is whenever I pressed the back button of the phone when I am the first activity of the application, application's service is also get closed.

for making background service then in android we have to extends Service class same as we are extends Activity in our application. And when you are extends service in your class then it will works as Background service. Then it will run until you uninstall your application from mobile or you are stop this service manually from settings.

More details ofService class and example of service .

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