Android Blitz: Basics of activity

Source: Internet
Author: User
Tags exit in

The life cycle of the 1,activity must call three methods, OnCreate () and OnStart ()--onresume (), with AAA (1) The parent activity initiates the child activity, the child actvity exits, the parent The Activity call order is as follows AAA--onfreeze ()--onPause ()--onStop ()--Onrestart ()--OnStart (), Onresume () ... (2) The user clicks Home, the actvity call order is as follows AAA--onfreeze ()--onPause ()--onStop ()--maybe--OnDestroy () –maybe (3 Call Finish (), the activity call order is as follows AAA--onPause ()-OnStop ()-OnDestroy () (4) Show dialog on activity, activity call The order below AAA (5) shows transparent or non-full-screen activity on the parent activity, the activity call order is as follows AAA--onfreeze ()-OnPause () (6) The device goes to sleep, the activity In the order below AAA--onfreeze ()--onPause ()

2, if the background activity is reclaimed by the system for some reason, the current state is saved by Onsaveinstancestate ().

3, how do I exit Activity? How do I safely exit a application that has called multiple Activity? For a single Activity application, the exit is simple, just finish (). You can also use the killprocess () and System.exit () methods.
for multiple activity, there are several ways to do this:
1), throw exception forced exit: The method by throwing exceptions, so that the program force Close. Validation is possible, however, the problem that needs to be addressed is how to make the program end without ejecting the Force Close window. 2), record open activity: Every activity that opens, record it. When you need to exit, close each Activity. 3), send a specific broadcast: when the need to end the application, send a specific broadcast, each Activity received the broadcast, close. 4), recursive exit in the opening of new Activity using Startactivityforresult, and then add their own flag, in the Onactivityresult processing,recursive shutdown. In addition to the first, it is to find a way to end each Activity, and indirectly achieve the purpose.but it's also not perfect. You will find that if your application has nosensor for each activity, at the end of two activity, SEnsor may be in effect.

4




































From for notes (Wiz)

Android Blitz: Basics of activity

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.