jgro
jgro

Reputation: 173

How to prevent a user from stopping an Android service?

I created an Android app and need to make it difficult for users to stop the main service that the app spawns during its startup process. This is for a rooted Jelly Bean 4.1.2 device. Here are some steps I've taken so far:

The steps I've taken so far takes care of most normal ways a user would stop/disable an app/process; however, when you check the running apps list in Settings -> Application manager -> Running, users can still hit the 'Stop' button on the long-running service that was started by the app (see picture below):

Service from Running Apps

Is there any way to prevent users from stopping the service here? Or what's the best way to restart a service when a user hits this stop button? I tried putting some code in the service's onDisable() function, but that function does not seem to be called in this case.

Any help would be appreciated!

Upvotes: 0

Views: 1503

Answers (2)

gor
gor

Reputation: 11

As explained above does not have this option unless it is executed as root, but you can create an AlarmManager when starting your service that runs from time to time, the system will run if the service is not running, it will be created again.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006539

Is there any way to prevent users from stopping the service here?

Having your app be a device administrator probably blocks this. It definitely blocks the "Force Stop" option.

I tried putting some code in the service's onDisable() function, but that function does not seem to be called in this case.

Since there is no onDisable() on a Service, this is not surprising.

This is a security app for an enterprise, so its expected to be continuously running.

There is nothing intrinsic to "a security app for an enterprise" that would require it "to be continuously running".

Upvotes: 0

Related Questions