Android Activity Summary

Source: Internet
Author: User
Document directory
  • What is Activity?
  •   Activity
  • Please refer to the following link for more information:
Content Overview

• Inheritance relationship of Activity

• Context in Android
• How Acitivy is actually instantiated
• Activity Lifecycle
• Activity startup mode, Task & Back Stack, process and thread, Intent. FLAG_ACTIVITY *

• Relationship between Activity, Window, and View

• Android message

Content

What is Activity?

• Is an application component that provides a screen for user interaction. It is not an interface.
  Activity

• Java. lang. Object
• Using android. content. Context
• Upgrade android. content. ContextWrapper

Using android. view. ContextThemeWrapper
• Launch android. app. Activity

Please refer to the following link for more information:

• Connect to the global information of the Android Application Environment
Port.
• Chinese Translation: Context
• Handle and environment variable.
What is the role of zookeeper encryption Context?
• Context literally indicates the Context, which is located in the android of the framework package. content. in Context, this type is actually LONG, similar to the Handle statement Handle in Win32. Many methods need to use Context to identify the caller's instance. For example, the first parameter of T oast is Context, this is usually used directly in the Activity, which indicates that the caller's instance is Activity, and when the onClick (View view) method of a button is called, when we use this, an error is reported, so we may use ActivityName. this is mainly because
The classes that implement Context mainly have several unique modules of Android.
Activities, services, and BroadcastReceiver

Activity Lifecycle
• 1. events triggered by Activity from creation to running state
OnCreate () --> onStart --> onResume () • 2. events triggered from the running state to the stop State
OnPause () ---> onStop ()
• 3. onRestart () --> onStart () ---> onResume ()
• 4. The onPause () event triggered from the running state to the paused state ()
• 5. Event onResume () triggered from the paused state to the running state ()
Lifecycle lifecycle Lifecycle
• A. Open the response
Use onCreate-onStart-onResume to call all three methods at the beginning.
• B. switch from the first activity to the second activity: first
Will onPause the first Shard, and then onCreate-> onStart-> onResume, the last in onStop
• C. Switch from second to first: the content is the same as the previous step.
• D. Press the back key of the mobile phone: First onPause is the first
When there are too many requests before the onRestart-> onStart-> onResume

Activity startup Method

• Activity has four loading modes:

• Standard
• SingleTop
• SingleTask
• SingleInstance
The startup method of zookeeper Activity • Standard
• When singleTop is started, if it is at the top, NewIntent will arrive at this instance. If it is not at the top, it will be the second instance.
• SingleTask when an instance exists in the Task, the NewIntent is connected to the instance,
• SingleInstance creates a separate task to store this instance. This instance is used for every hop.
• OnNewIntent onStart onResume
Too many rows into FLAG_ACTIVITY_REORDER_TO
• If four activities: A, B, C, and D have been started,
In the D Activity, I want to start another Actvity B, but it does not change to A, B, C, D, B, but A, C, D, B, the code can be written as follows: intent. addFlags (Intent. FLAG_ACTIVI TY_REORDER_TO_FRONT );
When there are too many other users
Worker FLAG_ACTIVITY_NEW_TASK
• For example, stack 1 is a B C. C jumps to D through intent, and the intent adds the FLAG_ACTIVITY_NEW_TASK tag. If D is in Manifest. task affinity is added to the Declaration in xml, which is different from the affinity of stack 1. the system first checks whether
The same task stack as T askaffinity of D exists. If yes, D is pushed into that stack. If not, A New affinity stack of D is created to push it. If Task affinity of D is not set by default, or is the same as the affinity of stack 1, it is pushed to stack 1 and changed
Then merge into a B C D.
Zookeeper extends FLAG_ACTIVITY_NO_HISTORY FLAG_ACTIVITY_SINGLE_TOP
• For example, the current stack is a B C. C jumps to D through intent. If the intent adds the FLAG_ACTIVITY_NO_HISTORY flag, the content of D is displayed on the interface, but it is not pressed into the stack. If you press the return key and return to C, the stack is still a B C. If the stack jumps to "E" again in "D" at this time, the situation of the stack changes to "a B C E". Then, press the return key to return to "C" because "D" is not pushed into the stack at all.
• FLAG_ACTIVITY_SINGLE_TOP: similar to the singleTop class of the Launch mode of the previous Activity. If this flag is added to an intent, and
The target activity of the intent is the top of the stack.
Please refer to the following link for more information: FLAG_ACTIVITY_SINGLE_TOP
• If four activities have been started: A, B, C, and D. In D, to B, remove C D. Use: Intent. FLAG_ACTIVITY_CLEAR_T OP
• Add Intent. FLAG_ACTIVITY_SINGLE if you do not want to re-create a new B for sequence.
• Intent. setFlags (Intent. FLAG_ACTIVITY_SI NGLE_TOP | Intent. FLAG_ACTIVITY_CLEAR_TOP );

• Similar to singleTask

There are five process levels in Android.

• 1) Foreground Process
• In Activity Resume () Status
• Is In The status of interacting with the bound Service
• The service is running on the frontend. (startForeground () is called)
• The Service lifecycle function is being executed (onCreate (), onStart (), onDestroy ())
• BroadcastReceiver is executing the onReceive () method
User response is required to kill Foreground Process

When the program is started, the program is started.

Bytes

Zookeeper extends PackManager and ActivityManager

1. Related to PackageManager
PackageManager Problems
This type of API is an encapsulation of all data structures based on loading information, including the following functions:

Install and uninstall an Application query permission information query Application-related information
(Application, activity, aggreger, service, provider, and related attributes)
Query installed applications, delete permission, clear user data, cache, code segments, etc.

Zookeeper has been released. zookeeper has been Launcher

• The first program to be loaded after the system starts • entry to other applications
• HomeScreen

Relationship Between Activity, Window, and View

• Activity calls the attach method before onCreate, and creates a window object in the attach method. When a window object is created, the tree creates a Decor object. The user calls setContentView in the Activity, and then calls setContentView of window. In this case, the user checks whether DecorView exists. If not, the user creates a DecorView object, add the user's View to the DecorView.

Android message

• Several classes about message mechanisms • Handler
• Message
• MessageQueue
• Logoff
Too many Android messages
• 1. Logoff: (equivalent to a tunnel) a thread can generate a logoff object for the Queue to manage the Message Queue (fleet, Message tunnel) in the thread ).
• 2. Handler: You can construct a Handler object to communicate with logoff so that new messages can be pushed to the Message Queue, or receive messages sent by logoff (extracted from the Message Queue.
• 3. Message Queue: used to store messages placed by a thread.
• 4. thread: the UI thread is usually the main
When Android starts the program
How is the actual instantiation of a dynamic workflow Activity?

Activity and binder

• From a macro perspective
Check Binder, Service, and Service Manager and describe their respective concepts. In the concept space of Linux, Android design activities are hosted in different processes, and services are hosted in different processes and activities between different processes, the data to be exchanged between services belongs to IPC. The Binder is a lightweight IPC framework designed for Activity communication.
• The entire application startup process of the activity: • Launch 1. Step1-Step 11: Launcher access
Inter-process communication through the Binder
Call Stack

• 0: dalvik. system. VMStack. getThreadStack Trace (Native 1: java. lang. Thread. getStackTrace (Thread. java: 737)
• 2: app. android. demo. activity. MainTestActiv ity $ 1.run( MainTestActivity. java: 40) 3: android. OS. Handler. handleCallback (Han dler. java: 587)
• 4: android. OS. Handler. dispatchMessage (H andler. java: 92)
• 5: android. OS. lorule. loop (lorule. java: 123
When there are too many other users)
•••••
••
Activity call stack
 
Every application uses ActivityThread. main () as the entry to process messages cyclically. For a worker process, we need this closed Processing framework.
Bytes
Relationship between HistoryRecord and HistoryRecord

• In the whole system, the Activity actually has two bodies. History an Activity that communicates with the application programmer in the application process, and History Record that has the management function in AMS. All activities in the application process are registered in the mActivity array of the ActivityThread instance, while at the AM end, the HistroytRecord instance is placed in the mHistroy stack. The mHistory stack is the place where Android manages the Activity. The Activity that the User sees is placed on the top of the stack.
• The relationship between Activity and HistrotyRecord can be expressed.
When there are too many other than the following:
When there are already too many threads, there are already too many threads

Related Article

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.