Recently looked at this thing for a long time, to share to everyone,
The principle is very simple, an activity in the Manifet declaration of Android:parentactivityname, this time through the activity in the upper left corner of the return button click Back,
The parent activity that initiates the declaration will always call the parent activity's OnDestroy method, as described below:
<activity Android:name="Com.example.helloworld.DisplayMessageActivity" Android:label="@string/title_activity_display_message" Android:parentactivityname="Com.example.helloworld.MainActivity" > <meta-data Android:name="Android.support.PARENT_ACTIVITY" Android:value="Com.example.helloworld.MainActivity" /> </activity>
Displaymessageactivity is the child activity, and mainactivity is the parent activity, clickDisplaymessageactivity the upper left corner of the button is returned, the invocation logic is as follows:
mainactivity.OnDestroy()mainactivity.onCreate(NULL)mainactivity.OnStart()
Solutions are:
To set the Mainactivity property Android:launchmode=singletop
by the way, the role of Android:parentactivityname is to add a return button to the upper left corner of the child activity, the specific information is as follows:
Android 4.1 Improves performance, enhances user experience App Stack Navigation: Change the contents of the fallback stack by setting android:parentactivityname if there is no parentactivity in the stack , the composition stack, through Onpreparenavigateuptaskstack () changes the contents of the parentactivity.
After setting the Android:parentactivityname, click the Child activity return key, the parent activity always calls the solution of OnDestroy ()