My app works like this, the user write down a time in minutes, for example 40. Then the app will call an alarm in 40 minutes from now. It doesn't matter whether the app is active or running in background it still works.
My issue is this, since I use the method System.currentTimeMillis(); then it makes my app dependent on the system time. So if i change my system time in the settings, then my alarm app will not be called on the set time, it will change.
for example: If time is 10:00am and I set the alarm to be called in 20 minutes from now, then it will be called 10:20am. However if I go to settings and change system time to 9:00am after setting the alarm, then my app will be called from 100minutes from now. How do i prevent this, so that when the time for alarm is set, and whatever the system time is, the alarm will be called after those minutes.
I have checked this out Date and time change listener in Android? and it's not the same, since it didn't work for me, nor did i fully understand it.
here is my code:
public void newSetAlarm(View view) {
timeEntered = Integer.parseInt(editTextForTime.getText().toString());
Intent AlarmIntent = new Intent(this, Alarm.class);
AlarmIntent.putExtra(TIME_LEFT, timeEntered);
pendingIntentForAlarm = PendingIntent.getBroadcast(getApplicationContext(), 0, AlarmIntent, 0);
amAlarm = (AlarmManager) getSystemService(ALARM_SERVICE);
amAlarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeEntered * 60000, pendingIntentForAlarm);}