After setting android: parentActivityName, click the return key of the sub-Activity. The parent Activity always calls the OnDestroy () solution,

Source: Internet
Author: User

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. Click
When 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.