How to disable force stop button or restart the servcie automatically after force stopping the app?

3.5k views Asked by At

i am tracking my employee's current location but if user force stops the app it stop the service and doesn't restart the service until user open the application.

So please tell me how to disable force stop button or restart the service automatically.

I know there are lots of question related to this none of them is working fro me.

2

There are 2 answers

0
CommonsWare On

Neither is strictly possible. The only apps that can have "Force Stop" disabled in Settings are ones pre-installed on the device. And the point behind "Force Stop" is that your app should never run again, until manually launched.

This is not a technical problem, but a managerial one. If you do not want employees force-stopping your app, ensure that there are suitable penalties for doing so.

You are welcome to try to have some sort of separate "watchdog" app that monitors the first app and restarts it if needed. But then all the user needs to do is to get rid of the watchdog before getting rid of the main app.

2
RAAAAM On

Disabling the force Stop is not possible, but we can do the restart. In onCreate method of main activity initialize a PendingIntent member:

intent = PendingIntent.getActivity(YourApplication.getInstance().getBaseContext(), 0,
            new Intent(getIntent()), getIntent().getFlags());

:

AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
System.exit(2);

Without calling System.exit() will not work. This code will restart your application after 2 seconds.

Hope this will help you. Accept if the answer which you are looking for.