After setting the Android:parentactivityname, click the Child activity return key, the parent activity always calls the solution of OnDestroy ()

Source: Internet
Author: User

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, click
Displaymessageactivity 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 ()

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.