Service getting stopped even after using Alarm Manager
I need to run some functionality in my service all the time.
So I have used Alarm Manager to make my Service alive.
I am using invoking Service for each 30 mins.
But If I keep my android device idle for long time( I tested by kept the device idle for overnight) I observed that my Service is not executing my functions.
I can 开发者_Python百科see the logs only upto nearly 2 hour's but after that my Service not running..
I just want know that how I can make my Service alive all the times..
Pl. help in this.
Application Services cannot be persisted. http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/
You have 3 options ([http://engineersaredumb.blogspot.com/2011/02/persistent-services-in-android.html][1] by https://stackoverflow.com/users/638122/andrew)
- If you need services to wake up regularly, work and die, use the
AlarmManager
- If you need need your service to run continuously for a limited period of time, like a Music
player,
setForeground()
on the service - If you need your service to keep running, but you can live with
interruptions from time to time, return
START_STICKY
fromonStartCommand()
All in all, Android will not let your Service run forever (unless it is a System service) .
精彩评论