Reputation:
I prepared for my application alarm manager. I need run this every hour and check if data is changed.
I have set the alarm manager like this:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, 1);
android.app.AlarmManager alarmMgr = (android.app.AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(mContext, AnalysisNotificationReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, ALARM_ID, intent, 0);
if (Calendar.getInstance().after(cal)) {
cal.add(Calendar.DAY_OF_MONTH, 1);
}
alarmMgr.setRepeating(android.app.AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60 * 60 * 1000, pendingIntent);
It's should work in every 60 minutes I'm not sure if I set correctly but doesn't work when app close.
Anyone have a idea? Thanks
Upvotes: 2
Views: 1755
Reputation: 1324
You can try this, it worked for me
AlarmManager alarmManager= (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent scheduleServiceExecuterIntent = new Intent(this, ScheduledServiceExecuter.class);
scheduleServiceExecuterIntent.putExtra("state", "Main");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, request_code, intent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, AlarmManager.INTERVAL_HOUR, pendingIntent);
Upvotes: 0