简体   繁体   中英

Which should I use class for the stopwatch to run in the background. “IntentService” or “service”

what service class should I use for the stopwatch that will run on the background

Which one should I use in terms of performance.

在此处输入图片说明

Here is an old question with loads of answers regarding differences between Service and IntentService. Maybe you can find something there.

From personal experience i'd say they are not that much different. Just the way you use them. I would say stick with the one you think fits your application best overall.

Service vs IntentService

You should use foreground service (with Service instead of IntentService ) in this case.

Reasons:

  • Android Oreo 8.0 defined Background Execution Limits . So you will not be guaranteed of service life.
  • Your app is also killed in Doze mode & Standby .
  • If you are running a continuous service with a long thread & start-sticky then your app is being suspected by optimization apps and OS. Your app will be considered battery draining.
  • Intentservice kills itself when work is done. Whether normal Service fits your requirement where only you have controls of your service.

Solution:

As i said make normal service as foreground service. See here . That will notify user till your service is running . And it will not be killed by OS due to any above reason.

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