preface
Activity
Belong toAndroid
One of the four components of- This article will be fully analyzed
Activity
, serve 1 portionActivity
Learning guide, including its life cycle, startup mode, startup mode and so on, I hope you will like it.
directory
Definition 1.
An activity is a presentation component
It is one of the four components of Android: Activity, Service, BroadcastReceiver, and ContentProvider
2. The role
Display interface & interact with the user
- a
Activity
Usually an interface is the only one of the four components that can be perceived by the user- Each activity is implemented as a separate class, & inherited from the activity base class
Activity
Through betweenIntent
communicate
3. Life cycle
- The details are shown below.
For more details, see Android Basics: the Activity lifecycle in 3 minutes
4. Start mode
Activity
There are four boot modes, as follows
- The differences between the four boot modes
For more details, see Android Basics: The most easy-to-understand Activity startup mode
5. Startup mode
- Start the
Activity
The main way is: explicitIntent
& implicitIntent
- Detailed introduction is as follows:
5.1 Explicit Intent (three types)
Intent = new Intent(this, secondActivity.class); startActivity(intent); Intent Intent = new Intent(); / / way 1: the package name + the name of the class / / parameters 1 = package name / / 2 = to start the fully qualified name of a class of intent. SetClassName (" com. Hc. Hctest ", "com. Hc. Hctest. SecondActivity"); // Method 2: Context+ class name // parameter 1 = Context, Can be directly introduced to the Activity / 2 = / parameters to start the fully qualified name of a class of intent. SetClassName (this, "com. Hc. Hctest. SecondActivity"); startActivity(intent); ComponentName () = new Intent(); ComponentName cn = new ComponentName("com.hc.hctest", "com.hc.hctest.SecondActivity"); intent.setComponent(cn); startActivity(intent);Copy the code
5.2 the implicit Intent
Intent = new Intent(); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addCategory("com.hc.second"); intent.setAction("com.hc.action"); startActivity(intent);Copy the code
5.3 Matching Rules
Android: The Trivia of Intent components (Introduction, Usage, etc.)
6. Start the process
The startup process of an Activity is as follows:
6.1 sketch
6.2 Description
When the request starts the Activity:
Launcher
The process byBinder
Drive to theActivityManagerService
Class astartActivity
Requests;ActivityManagerService
Upon receiving the request, the class calls theActivityStack
Class send startActivity
The request;ActivityStack
Class records what to startActivity
Information & adjustmentActivity
Stack puts it at the top of the stack and passesBinder
Driver willActivity
The startup information is passed toApplicationThread
In the thread (i.eBinder
Thread)ApplicationThread
Thread throughHandler
willActivity
Is sent to the main threadActivityThread
- The main thread
ActivityThread
Class receives the message & request and passesClassLoader
Mechanism loads correspondingActivity
Class, final callActivity
theThe onCreate ()
, and finally start complete
7. The cause of stagnation
The main reasons for Activity stagnation are as follows:
This is a comprehensive & detailed guide to memory optimization: Android performance optimization: Hand-in-hand with you to fully understand memory leaks & performance optimization solutions for Android: Those little things about Bitmap image resource optimization Android performance optimization: hand in hand with you to fully understand the drawing optimization Android performance optimization: layout optimization detailed analysis (including, explain)
8. Accelerated startup mode
The way to speed up an Activity is summarized as follows:
9. Cache mode (state saving)
- Problem description
- specify
10. Interaction between activities and fragments
- There are interfaces, bundles, and broadcasts
- Implement communication between Activity and Fragment (including Demo)
This concludes the tutorial on Activity, one of the four components of Android.
11. A summary
-
This article covered activities thoroughly, and you should now be familiar with activities
-
In my next post, I’ll cover Android. If you’re interested, keep an eye out for Carson_Ho’s Android development notes