I have 2 questions:
How do some android app make their service restart even if killed from task manager? A good example is Lookout security app. What I guess is that it has registered for all common events that are announced like app installed - unistalled, interenet available ,etc. Is this a way to keep your service running ? Another solution I found was to make 2 services monitoring each other, so if one gets killed restart another. Which one would be a proper approach ?
Is there any way in android to start booting automatically(if device is switched off) once connected to power source ? I have never heard t开发者_JAVA百科his on mobile platform. This is possible for PC through bios feature. Can it be done on android ? Any ideas welcome.
1.) This is simple. All you have to do is return Service.START_STICKY
from the services onStart()
method. This tells the android OS to resume the service ANY TIME it is killed EXCEPT with a call to stopService()
2.) The only way this is possible is by modifying the firmware of the phone. When the phone is off, the android OS hasn't yet been started so there's no way to create an application that can run before the OS has been booted.
Answering this my own old question ..
By registering for events as well as monitoring on apps may help but since 2.2 adds support for Service.START_STICKY this would rather be better option unless your app can't wait for O.S. to start. ( Like in case its antivirus which needs to be awake all time ).
Not a solution yet. Support may come up if provided an option ( for e.g. like BIOS has this feature for PC ).
精彩评论