Disabling "Force Stop" Button in Android

This is not remotely possible, for great reason.

You should tell her that making this possible would be a huge security disaster. Imagine what would happen if you could create apps which just ate at your processor time by holding a wake lock, and you couldn't kill them. This would be horrible.

In general, if you're wondering if you can modify the "extra-app" behavior of the device, the answer is usually *no*. You should take the viewpoint that nothing on the device is yours to control besides your app and (to a limited extent) the resources to which you're granted access.

No other app has this kind of control, so it's not reasonable to expect that your client's would either. However, the fact that she's asking for this control usually implies something else: that they are worried the user will stop the app and then something bad will happen (the locations will stop being synced, data will stop being sent out to the net, etc...). This would imply that you should look into improving the resilience of the app to different situations. Remember, your app can even be killed off at any time by Android (for example, in the case of low memory).


From ICS, disabling Force stop is possible. If your app has an active device admin then the framework will not allow user to kill the process


How to disable the "Force Stop" button

Short answer: Use the Device Administration API.

How to explain this to my client?

Show this to your client. It is a nice slideshow providing an easy-to-understand overview of the Device Administration API and its uses.

How do I demonstrate that it works?

Yes, back to your job. Use the API link provided above and the Api Demos included in Google's sample collection to figure out how to integrate this into your app.

  1. Build the demo and run it on your device.
  2. Choose API Demos->App->Device Admin->General->Enable admin.
  3. Choose Activate once the Device Administration API prompts you with its enabling screen.
  4. Exit the app and attempt to manage the app via your device's settings menu (specifics for this step varies by device).
  5. When viewing the Api Demo's "app info" screen, you should see both Force Stop and Uninstall are disabled.

How do I do this in my own app?

Review DeviceAdminSample.java in the Api Demos app for inspiration. You will need the following:

The following code is what brings up the activation screen:

                        // Launch the activity to have the user enable our admin.
                    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
                    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                            mActivity.getString(R.string.add_admin_extra_app_text));
                    startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);

However, there are a few other pieces you will need to get this to work:

  1. A broadcast receiver that derives from DeviceAdminReceiver.
  2. Entries in your manifest file that refer to the above broadcast receiver.
  3. Permissions in your manifest for using the Device Administrator API.
  4. An xml file stating what policies your app can access.

All of this can be found in the above links. Good luck with your client!


I think the device screen shot has confused us. Even I can show my application that is installed on the device and the "Force Stop" button is disabled. Where as I have not done any thing specific to that.

The reason of the "Force Stop" button being disabled is, that particular application is NOT running currently. Hence there is not meaning in having the button enabled. @Rhama you can ask your client to start the application once, press the home button of the device, and goto the settings and see. Surely the "Force Stop" button will be enabled this time.

Regards,

Rajan

Tags:

Android