0

AlarmManger is not firing in XIAOMI phones when app is in killed state, It is working fine in foreground state, after killing its not triggering at all.

final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, LocationUpdaterService.class);
final PendingIntent wakeupIntent = PendingIntent.getService(context, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

final int INTERVAL = 1000 * 60;
final int DELAY = 5000;

alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, DELAY,
                    INTERVAL, wakeupIntent);

I referred this answer Answer. But not solve the problem.

Is there any other solution for this problem?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74
  • What do you mean by "Killed state"? Do you mean the force stop button in the app info screen? If so, clearing the alarm manager is the wanted behaviour. (It is also mentioned in the warning dialog, that the app might behave not correctly) – Christopher Feb 14 '17 at 11:30
  • How exactly do you start and kill your app? – Kirill Feb 14 '17 at 11:31
  • @Christopher and @g4s8 I want perform some background job even the app is not in running state, I start some task when app in running and the task will end after performing another action. If the user `kill`(Completely closes the app not in recent app tray also) before performing another action the service should be keep on running. The same code will working in nexus phone correctly. – Naveen Kumar M Feb 14 '17 at 11:34
  • So, kill means swipe away in task manager in your wording? Which service? For a service you can use e.g. START_STICKY in your onStartCommand. – Christopher Feb 14 '17 at 11:37
  • Yes exactly @Christopher – Naveen Kumar M Feb 14 '17 at 11:38

0 Answers0