Can we use setrepeating in alarmmanager with changing values? For instance,
alarm.setRepeating(AlarmManager.RTC_WAKEUP, 0,
AlarmManager.INTERVAL_DAY*14, pi);
sets the interval to be 14 days. But if my phone restarts the alarm resets from start. I can write the value for the next alarm to file on SD card, but i am confused that how to call that value in alarm manager?
---------------------------------UPDATE 2-----------------------
The updated logic is: In broadcast receiver:
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
In Main Activity:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
long nextTime = prefs.getLong("timerval", 0);
Intent ishintent = new Intent(this, MyService.class);
PendingIntent pi = PendingIntent.getService(this, 0, ishintent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, nextTime,
AlarmManager.INTERVAL_DAY*14, pi);
While, MyService is a service that start my actual activity, and in that activity, when user clicks "Submit" button, after saving the data, the next timer fire time is calculated and saved like this:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Editor editor = prefs.edit();
Long nextint = System.currentTimeMillis() + 60000;
editor.putLong("timerval", nextint );
editor.commit();
But the issue is that on phone restart app still pop ups. Any ideas?