Android kills schedule every minute

I want to schedule a service to start every minute and check if my application is running. (I want to open the application again if it is closed). In addition, I still want this service to start every minute if my application was killed by the task manager. Thanks!

+3
source share
2 answers

Also, I still want this service to start every minute if my application was killed by task manager

This is not possible as of Android 3.1. If the user goes into Settings and force = stops your application, nothing from your application will start again until the user manually launches one of your components.

If your process is completed for other reasons (for example, the usual killer application from the Play Store, distracting your task from the list of recent tasks), your alarms scheduled with AlarmManager should remain intact at the suggestion of Lucifer.

im writes the application β€œParental Control”, which is installed on the daughter phone.

Any child smart enough to use the phone will be smart enough to restart their device in safe mode and get rid of your application.

+2
source

Use the AlarmManager class, it works even if your device is in sleep mode.

 private static Intent alarmIntent = null; private static PendingIntent pendingIntent = null; private static AlarmManager alarmManager = null; // First Creating an Intent alarmIntent = new Intent ( context, yourClass.class ); // Create an Pending Intent which will Broadcast the Intent pendingIntent = PendingIntent.getBroadcast(context, 234324243, alarmIntent, 0 ); // Set the AlarmManager class alarmManager = ( AlarmManager ) context.getSystemService( ConstantCodes.ALARM_SERVICE ); // Set Repeating time interval alarmManager.setRepeating( AlarmManager.RTC_WAKEUP, Interval * 1000, Interval * 1000, pendingIntent ); 

AlarmManager consumes less battery power than TimerTask or Thread. It works as a painless AsyncTask.

0
source

Source: https://habr.com/ru/post/1443221/


All Articles