Reputation: 178
is that posible to trigger one AlarmManager more than once ( not only 1:00 or 4:00 or 10:00 ), i mean, if i had 1 AlarmManager and could i execute the AlarmManager every 1:00, 4:00, 10:00 ? or is there other suggestion ?
if yes could you explain with code ?
this is my code and this just execute only every 12:00
public static void InitLoggingService(Context context) {
boolean bolLoggingServiceState = UtilitiesPreferences.GetLoggingServiceState(context);
Intent _Intent = new Intent(context, ServiceMain.class);
Intent SaveFileIntent = new Intent(context, ServiceLogger.class);
PendingIntent SaveFilePending = PendingIntent.getService(context, 0, SaveFileIntent, 0);
AlarmManager _AlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar _Calendar = Calendar.getInstance();
_Calendar.set(Calendar.HOUR_OF_DAY, 12);
if (bolLoggingServiceState == true){
context.startService(_Intent);
_AlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, _Calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, SaveFilePending);
}else{
context.stopService(_Intent);
InitStarterService(context);
_AlarmManager.cancel(SaveFilePending);
}
}
Upvotes: 0
Views: 111
Reputation: 2451
yes it is very much possible.It seems i don't need to tell u about writing services and receiver,my guess from above code is that u have already done it. I will tell u the logic to achieve what u want.
Few of the changes you need to do is call the alarmmanager
every time it fires i.e cancel the previous alarm and start a new one.In other words configure the alarm to execute only once.So every time your service gets called start a new alarm
Make a local db on mobile.Save the intervals at which u want to execute the alarm like 1,4,10 .Also in the same table put a field that would notify you about which interval was last executed. Then every time u make a new alarm call read from db the interval and execute accordingly.
Upvotes: 2