How do I prevent an application running in the background from being stopped by the user?

3

For example, an application that requires the cordenings of the device every 30 seconds and runs in the background, and the user can not force the device to stop manually.

    
asked by anonymous 01.10.2015 / 00:54

3 answers

2

So I understand you want to develop a "zombie" service that will work independently of the application. I do not advise you, you have to think about the battery life, even more using the GPS. If it is not an internal business application, you have a chance to have a high level of user rejection.

But ...

For this you will need a BroadcastReceiver:

No manifest:

<receiver
            android:name=".services.ReceiverCall"
            android:enabled="true"
            android:exported="false" >

            <intent-filter>
                <action android:name="SEU PACOTE.service.broadcast" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>

        </receiver>

The broadcast:

public class ReceiverCall extends BroadcastReceiver {     public ReceiverCall () {     }

    @Override
    public void onReceive(Context context, Intent intent) {
            context.startService(new Intent(context, SEU_SERVICE.class));
    }
}
    
26.10.2015 / 17:42
1

The way would be to create a sort of "runtime of a service" with an AlarmManager and schedule. There is no way to stop the user from stopping a service because there are several ways to stop a service. You'd better work on how to re-run your service.

With onStartCommand() , the service returns an integer that defines the reboot behavior, in case the service is terminated by the Android platform.

With these constants you can "control" your service processes and return your defaults:

  • Service.START_STICKY
  • Service.START_NOT_STICKY
  • Service.START_REDELIVER_INTENT

READ MORE HERE

    
01.10.2015 / 01:55
0

In fact I solved my problem using Services, putting my application to have administrator access level and starting a new service when the user destroys the application in the service's onDestroy method.

    
26.10.2015 / 20:43