0

My app has repeating tasks will be running every 5-minutes. I try to install same app twice and then the Alarm Manager don't fire to the broadcast for doing the task.

First time install it working all the time, until I reinstall the same version it stop repeating task. This is the problem with Alarm Manager. I don't get it.

This is my code:

     Intent intent = new Intent(context, CheckingPriceReceiver.class);
    intent.setAction("com.abccompany.trading");

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 
    REQ_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    long mInterval = 300000;
    long triggerTime = System.currentTimeMillis() + mInterval;

    AlarmManager alarmManager = (AlarmManager) 
    context.getSystemService(Context.ALARM_SERVICE);

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerTime, mInterval, pendingIntent);

I don't know how to fix it. Please help!!~~

Joyofio987
  • 173
  • 1
  • 9

1 Answers1

1

From this answer, Android Alarm What is the difference between four types of Alarm that AlarmManager provides and when to use what?

Also this tells the difference in the types of Alarms, https://developer.android.com/training/scheduling/alarms.html

ELAPSED_REALTIME

It will trigger since the boot time. Say if you set to 300000 then the alarm will trigger every 5 minutes and will not take the current time in consideration.

RTC

It will trigger as per the clock time meaning does not take boot time in consideration and will trigger at time as specified.

To wake up your device use this,

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, mInterval, pendingIntent);

else use this if you don't want to wake up the device

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerTime, mInterval, pendingIntent);
GeekDroid
  • 1,634
  • 3
  • 16
  • 36