When the Activity’s launch mode is singleTask or singleInstance. If an intent is used to pass a value, then the problem may arise that the intent’s value cannot be updated. That is, the value received for each Intent is the value received for the first time. Because the intent has not been updated. To update, you need to do two things.
1. Add a sentence to the sender Activity
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
2. The receiving Activity, plus a function, calls the method setIntent
protected void onNewIntent(Intent intent) { Log.i(TAG,"onNewIntent()"); super.onNewIntent(intent); setIntent(intent); int value = getIntent().getIntExtra("value_key", 0); Log.i(TAG,"value = "+value); }
Reproduced in: https://www.cnblogs.com/davesuen/p/3703436.html