I have a an Activity A, and a class B(extends BroadCastReceiver). From A, I am making an alarm like this:
Intent intent = new Intent(getApplicationContext(), TimerAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());
time.add(Calendar.SECOND, 5);
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), 3000, pendingIntent);
and this this B(name is TimerAlarmReceiver):
public class TimerAlarmReceiver extends BroadcastReceiver {
public static long TIME;
public static Boolean TimerOn=false;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm went off", Toast.LENGTH_SHORT).show();
Log.v("Tag", Long.toString(TimeKeeper.Time));
}
public static void setTime(long T)
{ TIME=TimerActivity.DMILLIS;
}
}
What I want to do is access something like a static variable from onReceive. I tried making a public static member in the activity.The logs show the correct set value for as long as the app runs. But if I force quit the app, the log in onReceive becomes 0.
So how do I pass an Initial value to B ? Something that keeps the value even if the app is closed(force quit).