Home Alarm Manage Issue
Reply: 1

Alarm Manage Issue

Joyofio987
1#
Joyofio987 Published in 2017-09-14 02:40:38Z

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!!~~

Bat Cat
2#
Bat Cat Reply to 2017-09-14 04:43:48Z

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);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30824 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO