Reputation: 1283
How can I 'clean' values from extra intent?
Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
...
Intent intent = new Intent(this, MyBroadcastReceiver .class);
intent.putExtra("valueOne", "valOne");
intent.putExtra("valueTwo", true);
intent.putExtra("valueThree", 1);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (5 * 1000), pendingIntent);
...
}
BroadcastReceiver:
@Override
public void onReceive(Context context, Intent intent) {
...
String valueOne= intent.getStringExtra("valueOne");
Boolean valueTwo= intent.getBooleanExtra("valueTwo", false);
Integer valueThree= intent.getIntExtra("valueThree", 0);
// Log.i("info", valueOne) >> valOne
// Log.i("info", valueTwo.toString()) >> false
// Log.i("info", valueThree.toString()) >> 1
...
}
If I change value in Activity and run application again, I get same values like in first start. I try delete app from my phone/virtual machine, clean project, but problem stay :(
Anybody help me?
Upvotes: 0
Views: 1545
Reputation:
First, i suggest you to format your code here. So that people here will be glad to read your problem code. Your code list above does NOT register any BroadcastReceiver to the system. You'd better to check out ApiDemo for more details.
And Also See this one
Upvotes: 2
Reputation: 20936
In the Pending Intent declaration try to set the following flag:
PendingIntent.FLAG_UPDATE_CURRENT
In your case it should be the following:
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Upvotes: 4