in thein Android development, we typically pass data between different pages, such asfromActivityaStartActivityband pass the data toActivityb inside, this is very simple, with INTETN add bundle can. But sometimes if youneed to let the background runActivityback to the front desk and pass the data there are some problems.
Usually, we passIntentKai toActivity, even if there is an identical runningActivity,the system will create a newActivityinstance and display it. At this point we'd better let the activity not start many times,through theAndroidmanifest.xmlConfigurationActivitythe load mode (Launchmode) to implement single-task mode (android:launchmode= "singleTask")。Singletaskthe time,start to aActivitya,if the system already exists Activitya instance, the system will start Activitya directly. At this point, however, the system will not invoke the usual cases where we process the request data.onCreatemethod instead of invoking theonnewintentmethod, as follows:
protected void Onnewintent (Intent Intent) {
Super.onnewintent (Intent);
Setintent (intent);
//Processing data, data=getintent (). Get ... ..
}Sometimes, however, the system may be killed in the background at any time. Activity , the system will also invoke the Activitya when it starts onCreate method without calling the onnewintent method. How do we deal with this at this time? is usually in onCreate and the onnewintent method, you can resolve the problem by invoking the same method that processes the data.
Attention:
protected void Onnewintent (Intent Intent) {
super.onnewintent (intent);
setintent (intent);
Process data, data=getintent (). Get .....
}
in the above method, if Setintent (intent) is not called, the data obtained by Getintent () will not be what you expect. so it's best to call setintent (intent) so that you can call Getintent () to get the data.
Acitivity data transfer processing in Singletask load mode