I have a problem with a text string attached to an alarm. It seems that when the alarm goes off, the line associated with the alarm is zero. Itโs clear that I made a mistake, but I donโt know where.
My code for setting the alarm:
static void set_alarm(long alarm_time_in_millis,Context cont,AlarmManager alarm_manager,String str) { Intent intent = new Intent(cont, to_call_when_alarm_goes_off.class); intent.putExtra("string_passed_in_bundle", str); Log.i("xx","set_alarm ["+str+"]");
The code for receiving the alarm is as follows:
public class to_call_when_alarm_goes_off extends BroadcastReceiver { Bundle bundle_from_whoever_called_this_activity; @Override public void onReceive(Context arg0, Intent arg1) { String str; bundle_from_whoever_called_this_activity = arg1.getExtras(); str = bundle_from_whoever_called_this_activity.getString("string_passed_in_bundle"); Log.i("xx","to_call_when_alarm_goes_off: TIME TO WAKE UP!!! ["+str+"]"); try { Intent i = new Intent(arg0, dingaling.class); i.putExtra("string_passed_in_bundle", str); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); arg0.startActivity(i); } catch (Exception e) { } } }
When I set the alarm and wait for it to start, the log file will show something like this
set_alarm [Go to meeting] to_call_when_alarm_goes_off: TIME TO WAKE UP!!! [null]
EDIT: Maybe some kind of "super." feature I forgot to call?
EDIT: I often get confused about which context is passed to various functions, for example. getBaseContext (), getApplicationContext (), "this", etc. If I had the wrong context linked somewhere, could this cause this problem?