开发者

How can I restart my app service if user stops (kills) it from settings?

开发者 https://www.devze.com 2023-03-30 06:45 出处:网络
What would be a way to restart my service when an unauthorized person kills it from the device settings? When the aut开发者_开发百科horized user wants to stop the service, I am providing a UI which re

What would be a way to restart my service when an unauthorized person kills it from the device settings? When the aut开发者_开发百科horized user wants to stop the service, I am providing a UI which requires a password.


Suggest a way to restart my service when user(unauthorized person) kill it from the device settings

They are not "unauthorized". It is their device, not yours.

In Android 3.1 (and possibly a bit earlier), you will not be able to restart your service by any means until the user launches one of your activities. If the user force-stops your process, you are prevented from ever running again until the user manually launches you.

For stopping the service I am providing a UI which requires a password

That will not be effective. Users will be able to stop your service via a task killer or the Manage Services screen, whether you like it or not. Please respect the wishes of the user.


Im afraid you are going to be fighting against the system to try to achieve this. This system was built to go on devices owned by average consumers. If the user wants your app to stop there is little you can do to disallow them from stopping it. Even if you do manage to come up with something that is effective at restarting your service there may be Task Killer apps out there that will catch on to you and start auto shutting you down each time you restart.

Bottom line is, it's their device, they get to choose what is running and what is not. I understand that there are perfectly reasonable use cases for needing a password to stop something but it would have to be handled at the system level to be 100% effective.


to restart any service which is terminated at run time then use

   public int onStartCommand(Intent intent,int flags,int startId)
    {
       .........//your service coding //
       ........................
       return Service.START_STICKY
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号