Hi,
I'm creating an intent that I'm pushing to the AlarmManager so that a
service will be run at a later time. I have a single string value I
need to pass with the intent so the service knows what to "do" when
it's onStart() is called.
Here is the code that sets up my intent and pushes it to the
AlarmManager
Intent myintent = new Intent();
myintent.setClass(mContext, RemindMeLater_Service.class);
myintent.putExtra("ReminderText", mEditText_Reminder.getText().toString
());
mPendingIntent = PendingIntent.getService(this, 0, myintent, 0);
// Use the AlarmManager to schedule the PendingIntent
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTime,
mPendingIntent);
Notice the line:
myintent.putExtra("ReminderText", mEditText_Reminder.getText().toString
());
Essentially I'm trying to "change" the extended data referenced by the
same name in the putExtra call. Note also that the "myintent" Intent
is freshly created everytime this block of code executes, so it should
be a new instantiated Intent object. The text that is put into the
extended data comes from an EditText view on my activity.
The code in the service that is trying to pull the string out is:
public void onStart(Intent intent, int startId) {
// Increment mReminderId to ensure each notification is unique to
this context
String reminderText = intent.getStringExtra("ReminderText");
//do stuff with the "reminderText" we just got out of the intent
// ...........
}
Seems pretty simple, and logical. So here comes the problem. This
works ONCE. The first time the intent is created and the extended
data is added with .putExtra( ), when the AlarmManager goes off and
starts the service, the remidnerText is exactly what I put in.
However, subsequent calls to this code, creating the intent, adding a
new string using .putExtra( ), the AlarmManager goes off, service gets
onStart() called, now the reminderText still has the same value from
the first call. It keeps holding onto the same value for ever until I
uninstall the .apk and reinstall (i.e. Rebuild ->Run through eclipse
on the emulator or a real device).
I've tried putting breakpoints right at this line and verified the new
string being passed into putExtra() has changed:
myintent.putExtra("ReminderText", mEditText_Reminder.getText().toString
());
And then a breakpoint at the service line and verified that it still
has the previous value:
String reminderText = intent.getStringExtra("ReminderText");
I'm a little lost at what to do next. Maybe the bundle that is
created is when I call putExtra() is being cached? I've tried doing
System.gc() right before I create my new intent each time and still no
luck. Thanks for any insight, I hope I've provided enough detail.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---