The Activity is started in singleTask mode. The solution for intent value passing is singletaskintent.
Reprinted please indicate the source, thank you http://blog.csdn.net/harryweasley/article/details/46557827
Because there is a message push function in the project, each time a message is pushed, FunctionActivity is enabled. In order to avoid re-enabling it, this Activity appears multiple times when you step back, change the Startup Mode of the Activity to singleTask.
In this way, the onNewIntent (Intent intent) method is called multiple times after the Activity is started.
When the activity transmits data through intent, if the activity is not started, the intent data will be obtained through getIntent () in the newly started activity. if the activity to be started already exists, the intent obtained through the getInten () method is the original intent of the started activity. in other words, intent data is not updated. in this way, the intent data obtained in the started activity is old data. if you want to obtain new data from intent each time, you need to call setIntent (Intent) in the onNewIntent (intent) method to set the latest intent. as follows:
@ Overrideprotected void onNewIntent (Intent intent) {super. onNewIntent (intent); Log. e ("tag", "onNewINtent executed"); setIntent (intent); String ringName = intent. getStringExtra ("ringName"); Log. e ("tag", ringName + "passed value"); if (ringName! = Null) {pager. setCurrentItem (1 );}}
Of course, if the Startup Mode of the activity is standard, re-create a new activity every time. In this way, the intent is the latest. You do not need to use setIntent to update the intent.
In my project, there are four Fragment items in FunctionActivity. In this way, I will not instantiate the function from other activities, and the latest intent cannot be obtained through the getIntent () method. Or in the onNewIntent method, share the updated intent through getIntent (). putExtras (intent);, as shown below:
@ Overrideprotected void onNewIntent (Intent intent) {super. onNewIntent (intent); Log. e ("tag", "onNewINtent executed"); setIntent (intent); getIntent (). putExtras (intent );}
In this way, you can call
@ Overridepublic void onResume () {super. onResume (); // The first time you enter this page, the following method will not be executed, because ringName is nullString ringName = getActivity (). getIntent (). getStringExtra ("ringName"); if (ringName! = Null) {newSound. setText (ringName); Log. e ("tag", ringName + "value to be saved"); SharedPreferenceUtil. setString (getActivity (), SharedPreferenceUtil. RINGTONE_NAME, ringName );}}
Note that Fragment must be called in the onResume method.