Reputation: 77
i want to know that is there any way i can prevent my android app from killing from task manager. Whether it's any third party app, clears from ram manager or user clicks force stop. i just don't want kill my app from background, It should be running.
Upvotes: 3
Views: 1775
Reputation: 47
How to disable the "Force Stop" button
Short answer: Use the Device Administration API.
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.
API Demos->App->Device Admin->General->Enable admin.
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:
All of this can be found in the above links. Good luck with your client!
Upvotes: 2
Reputation: 1600
This might be a dirty way to do this. But it worked for me.
Just override onDestroy()
method in service and start that service again.
@Override
public void onDestroy() {
Intent intent = new Intent(this,YourService.class);
startService(intent);
}
Upvotes: 0