My app has 2 different activities, let us name them A and B. I set an alarm in activity A with the time to trigger the alarm after 5 mins. I move to activity B and do some stuff there that takes less than a minute. I come back to activity A, what is happening here is that the alarm gets registered again and instead of the previous time of 5 mins, it takes 5 mins from now...For clarity Act A - register alarm - 5 mins to trigger a beep...Move to activity B, Act B - do some stuff - x mins...Move back to Act A - alarm registered again - x+5 mins to trigger a beep....
I dont want the above scenario to happen. I want to trigger the alarm at 5 mins only and not x+5? Any help please? It is really bugging me..Am on it from Thursday...
In act A
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent checkIntent = new Intent(getApplicationContext(),Alarm_class.class);
checkIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, checkIntent, 0);
if(PendingIntent.getBroadcast(getBaseContext(), 0, checkIntent, PendingIntent.FLAG_NO_CREATE) != null)
{
Log.d("kunal", "Alarm is running");
if(log_days_came.equals("Three"))
{
Log.d("kunal","3 days selected to zip log file.");
// am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 180000, pi);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 2*60000, pi);
Log.d("kunal","after the pending intent 3.");
}
}
else
{
if(log_days_came == null)
{
Toast.makeText(getApplicationContext(), "configure the days to zip log files", Toast.LENGTH_LONG).show();
Log.d("kunal", "Alarm is not running");
}
}
if(log_days_came.equals("Three"))
{
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(System.currentTimeMillis());
calendar2.add(Calendar.MINUTE, 3);
}
I go to act B...do some stuff...come back to act A...it calls the OnReceive of the alarm again, without the trigger expired...what am I doing wrong?