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
Read More:
- The intent solution cannot be updated in onrestart method
- Android can’t transfer value when using extras, bundle and intent
- Android android.intent.category Purpose and use of. Launcher
- The problem that the content extra data in the notification cannot be updated
- IBM MQ Reason 2538(MQRC_ HOST_ NOT_ An example of error reason
- Error receiving broadcast Intent { act=com.supersdk.listen.PayListen_defeat flg=0x10 (has extras)
- appear java.lang.NoClassDefFoundError A kind of reason and solution of the mistake
- Not allowed to bind to service Intent [How to Solve]
- Solution of toast not displaying in Android
- DirectX encountered “unresolved external symbol” when compiling on vs2015__ The solution and reason of “vsnwprintf”
- Error lnk2038: detected “0”_ ITERATOR_ DEBUG_ The reason and solution of the unmatched item of “level”
- The reason and solution of the error of join function: sequence item 0: expected STR instance, int found
- Connection authorization failure occurred. Reason: local security service non retryable error solution
- Android 9.0 error: net:ERR_ CLEARTEXT_ NOT_ Permitted solution
- Android studio compilation error: style attribute ‘@ android:attr/windowEnterAnimation ‘not found the ultimate solution
- In Vue, use echorts to report an error: “typeerror: cannot read property ‘init’ of undefined” error reporting reason and solution
- Android studio AAPT: error: attribute android:requestLegacyExternalStorage not found.
- Error in Cordova project execution command after Android studio upgrade: could not find gradle wrapper within Android SDK
- Android solution to the conflict of calling ontouch and onclick at the same time
- Android project error: could not resolve com.android.support .c onstraint:constraint-layout :2.0.2.