Reputation: 5317
I'm using AlarmManager
for widget update transactions. I've different interval values like 5, 10, 15, 30 minutes etc.
How to call AlarmManager
:
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyService.class);
pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
// Interval value, default 600 (600*1000 -> 10 min)
Long repeat = Long.parseLong(prefs.getString("update_preference", "600"));
// Set the manager
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(), 1000*repeat, pi);
So If user selects 5 or 10 minutes, it's okay. But if not, I mean, user selects bigger values like 15, 30, 60 minutes MyService
not working as soon as setRepetaing
.
What's difference or wrong?
Edit: It works instantly <30 minutes, but now work higher than 30 minutes with unique request codes.
Upvotes: 2
Views: 942
Reputation: 4199
pi = PendingIntent.getService(context, 12345, i, PendingIntent.FLAG_UPDATE_CURRENT);
This could work, "0" isn't the best choice for an unique id.
Upvotes: 2
Reputation: 15701
I think you have to use unique request code in PendingIntent
Mulitple Instances of Pending Intent
Upvotes: 2