I have an app that every minute launches an IntentService that gets the UsageStats and UsageEvents on this period. I used setExact() method of AlarmManager to set the moment that the IntentService is executed and on the onCreate method of the IntentService i call again to setExact() to schedule the execution of the IntentService the next minute. I did this because the method setRepeating() of AlarmManager didn't perform with accuracy on one minute periods. The code i use is:
alarmM.setExact(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime()+60000,alarmAppIntent);
This performs correctly most of times and when the device is charging. However, when the device is in normal use sometimes the service stops repeating every minute (i create a notification everytime the service executes to see if the service continues executing) and when the IntentService stops repeating Logcat says:
03-02 12:16:02.221 1173 12379 I ActivityManager: Process com.app.usage (pid 6390) has died
03-02 12:16:02.222 1173 1423 D DisplayManagerService: Display listener for pid 6390 died.
03-02 12:16:02.222 1173 12379 D ActivityManager: SVC-handleAppDiedLocked: app = ProcessRecord{73a4530 6390:com.app.usage/u0a251}, app.pid = 6390
03-02 12:16:02.222 1173 12379 D ActivityManager: cleanUpApplicationRecord -- 6390
03-02 12:16:02.222 1173 12379 D ActivityManager: SVC-mBroadcastQueues: com.android.server.am.BroadcastQueue@e800e85
03-02 12:16:02.222 1173 12379 D ActivityManager: SVC-mBroadcastQueues: com.android.server.am.BroadcastQueue@d0e4da
03-02 12:16:02.223 2049 2306 E WtProcessController: Error pid or pid not exist
03-02 12:16:02.315 1173 1378 D PerfServiceManager: [PerfService] MESSAGE_USER_DISABLE: 92
03-02 12:16:02.315 1173 1378 I libPerfService: [perfScnDisable] scenario:92
03-02 12:16:02.315 1173 1378 I libPerfService: 92: set max: -1, 0, -1,
03-02 12:16:02.316 1173 1378 I libPerfService: 92: set freq: -1, -1, 933000,
03-02 12:16:02.316 1173 1378 I libPerfService: 92: set gpu level: 0
03-02 12:16:02.447 3149 3166 I PerfService: PerfServiceNative_userEnableTimeoutMs:30, 1050
03-02 12:16:02.448 3149 3166 I PerfService: PerfServiceNative_notifyDisplayType:2
The device i am using is a Xiaomi Redmi Note 4 Pro with MIUI 9.2 (Android 6.0). I've tried to set no battery economizer to the app but the problem continues.
Is there some way to stop the app dying using other libraries or configuration?