After setting android: parentActivityName, click the return key of the sub-Activity. The parent Activity always calls the OnDestroy () solution,
I 've been checking this for a long time and share it with you,
The principle is very simple. An Activity declares android: parentActivityName in manifet. At this time, click the return button in the upper left corner of the Activity to return,
When a declared parent Activity is started, the OnDestroy method of the parent Activity is always called first, 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 a child Activity, while MainActivity is a parent Activity. ClickWhen the return button is displayed in the upper left corner of DisplayMessageActivity, the calling logic is as follows:
MainActivity.onDestroy()MainActivity.onCreate(null)MainActivity.onStart()
Solution:
Set MainActivity attribute android: launchMode = singleTop
By the way, supplement android: parentActivityName to add a return button to the Child Activity in the upper left corner. The details are as follows:
Android 4.1 improves performance and enhances user experienceApp stack navigation: changes the stack rollback content by setting android: parentActivityName. If no parentActivity exists in the stack, the stack is merged and the onPrepareNavigateUpTaskSTack () changes the content in parentActivity.