Android Activity Summary

Source: Internet
Author: User

Acitivity:
four statuses : Active, paused, stopped, destroyed
four modes of loading : standard, singletop,singletask,singleinstance;
Seven main methods : OnCreate (), OnStart (), Onrestart (), Onresume (), OnPause (), OnStop (), OnDestroy ();

OnCreate (): This method is called only once when an activity callback is created.

Onresume (): Called when the activity is resumed and must be called after calling OnStart ()

OnDestroy (): When the activity is destroyed callback, the method can only be called once.
Activity in Android is managing activity in the form of activity stacks , with the current activity being on top of the stack.
Detailed
Four states:
Active state: Current activity, user visible, can get focus.
Paused state: The user is visible and cannot get the focus.
Stop state: The user is not visible.
Destroy state: Activity ends.


four modes of loading;
Standard: Normal mode, which is the default mode.
Singletop:task Stack Top single case mode
Singletask:task in-stack single case mode
SingleInstance: Global Singleton mode
Android's management of activity:
Android uses task to manage activity, and when a user opens an Android app, Ankdroid creates a taskfor it.
Then launch the portal activityfor this app, (note: An application is composed of several activity combinations) the entry activity is
The activity of main and Lancher configured in <intent-filter..../>.
The application's task can be understood as an activity stack (first in and out), the activity that starts first is with the bottom of the stack, and then starts at the top of the stack.
The =====================================//code is as follows: ===================

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "com. Lzt.sqlitetry "Android:versioncode= "1"Android:versionname= "1.0" ><USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" /><ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" ><ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" ><Intent-filter><ActionAndroid:name="android.intent.action.MAIN"  /><categoryAndroid:name= "android.intent.category.LAUNCHER" /></Intent-filter></Activity></Application></Manifest>

=======================================================================
1. Default mode: Standard
When activity is loaded in this mode, a new activity instance is created on the original task stack each time the activity is started.
2.singleTop:
This mode is basically similar to standard mode, but with a little difference, if the activity you want to start is at the top of the stack, you don't have to create
An activity instance. Can understand the literal meaning
3.singleTask:
In this mode of activity, there is only one instance of the activity in the same task, which is divided into the following three cases:
* If the activated target activity does not exist, an activity will be created and added to the top of the stack.
* * If the target activity already exists and is at the top of the stack, then the same behavior as Singletop
If the target activity already exists but is not at the top of the stack, the system removes the task from all the activityon that activity.
Pushes the instance to the top of the stack.
4.singleInstance:
There can be only one instance of activity in the entire application and is located on a single stack.

The above four loading modes need to be configured in the file manifest: one of the properties of the activity: laucnchmode= "Singletop" | | " Singletask "
||" SingleInstance "
Another property of activity: exported= "ture" | | " False ", when True indicates that the activity can be started by another application.

==============================================================

The startup process for activity named a:
OnCreate ()--->onstart ()---->onresume ();
Activity that is currently named a, and then call Bactivity:
a.onpause ()-->b.oncreate ()---->b.onstart ()---->b.onresume ()---->a.onstop ();
Then callback the process of a:
B.onpause ()--->a.onrestart ()--->a.onstart ()--->a.onresume ()--->b.onstop ()--->b.ondestroy ();
Can be understood as playing a game, and then someone called.

Three possible situations when an activity is destroyed:
A:onpause ()--->onstop ()---ondestroy ();
B:onpause ()--->progresskill
C:onpause ()--->onstop ()--->progresskill
The CPU can save memory by killing some activity directly, depending on the situation.

Android Activity Summary

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.