Android Activity principle and its subclass description, androidactivity

Source: Internet
Author: User

Android Activity principle and its subclass description, androidactivity
Introduction

Activity is an Android application component that implements a user interaction window. We can fill the screen with la s or implement floating windows. An app is composed of multiple Actvitiy types, which use intent-filter to differentiate the primary-secondary relationship.
The following describes the Activity and its subclass and Other interfaces.

Details 1. Activity


2. ListActivity



3. ActivityGroup



4. TabActivity



5. PreferenceActivity



6. FragmentActivity


7. ListFragment



8. NativeActivity



9. ExpandableListActivity



10. LauncherActivity



11. AliasActivity


12. PreferenceFragment

13. ActivityCompat


14. ActivityUnitTestCase


Currently, Activity management involves two classes: 1. LocalActivityManager 2. ActivityManager. What have they done separately?





Lifecycle



There are three critical lifecycles.

From the initial call of onCreate (Bundle) to the final call of onDestroy () is called the complete life cycle. Activity will set all the "Global" statuses in onCreate () and release all the resources held in onDestroy. For example, if a background thread downloads data from the network, it may create this thread in onCreate () and stop it in onDestroy.

The life cycle is visible from the onStart () of the activity call to the onStop () of the call. During this period, the user can see the activity on the screen, although it is not necessarily in the foreground and may not interact with the user. Between the two methods, you can maintain the resources required for the activity to be displayed by the user. For example, you can register an IntentReceiver in onStart () to monitor environment changes that can affect your UI, when your UI is not displayed in front of the user, you can log out the IntentReceiver in onStop. The corresponding method is called whenever the activity is displayed or hidden in front of the user. Therefore, the onStart () and onStop () methods can be called multiple times throughout the lifecycle.

Starting from the onResume () call of the activity and calling the corresponding onPause (), the activity is called the foreground life cycle. During this period, the activity is in front of all other activities and interacts with the user. An activity can often switch between the resumed and paused States-for example, when the mobile phone goes to sleep, the activity results are returned, and the new intent arrives-so the code in the two methods should be very short..

The following Activity method defines the complete lifecycle of an activity. They are all hook methods. You can reload these methods to make the activity execute the operations you expect when the status changes. All activities should implement their own onCreate (Bundle) method for initialization settings; most of them should also implement the onPause () method to submit data modifications and prepare to terminate interaction with users. Although we plan to add more tools to the system to manage applications, most of the current activities still need to implement onFreeze () and perform corresponding state recovery in onCreate (Bundle. Other methods can be implemented as needed. when implementing these methods, you must call the corresponding methods in the parent class.


Android activity class and intent Problems

Each Activity requires a class to inherit,
Activity can be understood as an Application Scenario. If you think of it as a web page, it is a page.
You can jump between multiple activities, just as the webpage jumps to each other. You only need to set Intent, and do not need GetIntent
GetIntent is what the system does. When the system receives your Intent, it will automatically generate the class object instance of the page you want to jump to, and automatically callback the Oncreate method of the class, you only need to write down the UI initialization of your page in the Oncreate method.

Redirection can be implemented using the Intent mechanism as you said:
Intent intent = new Intent ();
Intent. setClass (this, Page. class );
This. startActivity (intent );
In this way, you can. The key is the setClass method. The first parameter is the current Activity, which is the class of the current page. The second parameter is the class of the other page.

Why is it a class rather than an object? Because Android wants you not to go to the instance to create a new page object, but to tell the system which page you want to jump to and the system will help you to create a new page object. Then the system will help you jump over. You should not control this process.

Continue:
After this. startActivity method is executed, the Page will jump from the current Page to the next Page you specified. In my example, the Page is called Page, which is also a class of extends Activity,

There is a premise that all activities (including this Page) must use the OnCreate () method of the Instance Activity. Because Activity is an abstract class and onCreate is a method of image extraction, you must implement it, fill in the complete method, write something in it, usually generate some, buttons, menus, pictures, text and so on to initialize the interface.

Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
Instance = this;
RequestWindowFeature (Window. FEATURE_NO_TITLE );
This. setContentView (R. layout. main );
// TODO
// Your code
}

There are also Onstop, onResume and other methods that can be implemented, but they can be selectively implemented instead of the image method. Not mandatory.

As for the configuration in xml, you need to fill in the paths of all activity page classes.
<Application android: icon = "@ drawable/icon" android: label = "@ string/app_name">
<Activity android: name = ". Mstar"
Android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "an ...... the remaining full text>

In android development, it is best to provide detailed examples of how to implement the methods defined in the activity class of non-activity class orientation.

Activity is a container of the image. Various controls (buttons, text, check boxes, etc.) are placed in the container to form the software interface ~ Activity is visible 38. If no control is added for Activity 28, create an activity01 Activity Class ko using the Public Class activity01 extends Activity {} like a blank form in Windows.

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.