Android development path 03, android path 03
I. Activity
1. how to define multiple activities in an application: ① define a class to inherit the Activity; ② in this class, rewrite the onCreate method in the Activity; ③ In AndroidManifest. register the Activity in the xml file;
2. How to start an Activity: ① generate an Intent object; ② call the setClass method to set the Activity to be started; ③ call the startActivity method to start the Activity
3. back stack in Android (return stack refers to the return button): the data structure of stack follows the principle of advanced and backward release. For example, we have three activities, which are A, B, c. We can access B through A, and enter C through B. That is to say, Activity A is our main Activity. When we enter the application, the first thing we see is A. At this moment, the elements at the top of the stack in the back stack are the objects of.
When A opens B, the B object will be added to the returned stack, and so on! When we click the return button, the Activity object at the top of the stack will be removed and destroyed; instead, the new elements at the top of the stack will be replaced; the operation of the return button is the opposite of the order in which we enter an Activity.
4. Concept of Activity lifecycle: the whole process from Activity creation to Activity extinction
5. Activity lifecycle method:
① OnCreate (): called when the Activity object is created;
② OnStart (): called when the Activity becomes visible;
③ OnResume (): This method is called when the Activity begins to prepare for interaction with the user;
④ OnPause (): This method is called before the system starts another Activity;
⑤ OnStop (): This method is called when the current Activity becomes invisible;
⑥ OnDestroy (): This method is called before the current Activity is destroyed;
7onrestart (): This method will be called before an Activity is started again;
6. activity object status: three states are officially declared. The first is Resumed: The Activity object is in the running state; the second is Paused: The other Activity is on the front end, but the Activity is still visible; the third type is Stoped: The other Activity is located at the front end and completely blocks the Activity;
Ii. Intent
1. Basic concepts of Intent objects: ① Intent is one of the Android application components; ② Intent objects represent an Intent in the Android system; ③ the most important content of Intent is action and data
2. Transmit data using Intent object: ① use putExtra () series methods to store data to Intent objects; ② use getExtra () series methods to retrieve data from Intent objects
3. Android thread
1. Two Methods of Thread implementation: ① inheriting the Thread class; ② implementing the Runnable interface;
2. mainThread (UI thread or main thread) and WorkerThread (responsible for data calculation): In an application, the main thread is usually used to receive user input, and feedback the operation results to the user. Therefore, some operations that may cause blocking must be placed in the Worker Thread.
Iii. Handler
1. the basic principle of Handler operation: Handler, logoff, and MessageQueue (the data structure of message queue and queue follows the principle of first-in-first-out) are involved, handler is responsible for adding the message object to the Message Queue. Looper is responsible for extracting the added message object. Looper calls handleMessage () method of Handler to process the message object.
2. Implement inter-thread communication through Handler