First, Reason:
When calling to Onnewintent (intent), you need to use setintent (intent) in Onnewintent () to assign the intent to the activity. Otherwise, the subsequent getintent () is to get old intent.
Second, onnewintent ()
In Intentactivity, override the following methods: OnCreate onStart onrestart onresume onPause onStop OnDestroy onnewintent
1, other application hair intent, do the following methods:
OnCreate
OnStart
Onresume
Method of Hair Intent:
Uri uri = uri.parse ("philn://blog.163.com");
Intent it = new Intent (Intent.action_view, URI);
StartActivity (IT)
2, receive intent statement:
<activity android:name= ". Intentactivity "android:launchmode=" Singletask "
Android:label= "@string/testname" >
<intent-filter>
<action android:name= "Android.intent.action.VIEW"/>
<category android:name= "Android.intent.category.DEFAULT"/>
<category android:name= "Android.intent.category.BROWSABLE"/>
<data android:scheme= "Philn"/>
</intent-filter>
</activity>
3, if the intentactivity is at the top of the task stack, that is, the previously opened activity, now in the OnPause, OnStop state, other applications to send intent, the order of execution is:
Onnewintent,onrestart,onstart,onresume.
When developing an Android application, it is very simple to start another activity from one activity and pass some data to the new activity, but it may be a little bit of a problem to have the activity in the background run back to the foreground and pass some data.
First, by default, the system creates a new activity instance and displays it when the activity is started by intent, even if there is already a running activity. Implement the single-task mode by configuring the load mode (launchmode) of the activity in Androidmanifest.xml as follows:
<activity android:label= "@string/app_name" android:launchmode= "Singletask" android:name= "Activity1" ></ Activity>
When the Launchmode is Singletask, the system will send the request to this instance by intent to an activity, if the system already has an instance, but this time, Instead of invoking the OnCreate method that normally handles the request data, the system calls the Onnewintent method, as follows:
protected void Onnewintent (Intent Intent) {
Super.onnewintent (Intent);
Setintent (intent);//must Store the new intent unless getintent () would return the old one
Processextradata ();
}
Don't forget that the system may kill the Activity in the background at any time, if this happens, then the system will call the OnCreate method, instead of calling the Onnewintent method, a good solution is to onCreate and onnewintent Method calls the same method that processes the data, as follows: public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Processextradata ();
}
protected void Onnewintent (Intent Intent) {
Super.onnewintent (Intent);
Setintent (intent);//must Store the new intent unless getintent () would return the old one
Processextradata ()
}
private void Processextradata () {
Intent Intent = Getintent ();
Use the data received here
}
Why do I have to call Setintent when I want to show onnewintent?