Section 5th Activity's manifest Configuration 5.1 activity Statement
Activity is a four-part component, and each activity defined in the code needs to be declared in a AndroidManifest.xml
file.
<manifest xmlns:android="Http://schemas.android.com/apk/res/android" package ="Com.anddle.activitytest"> <applicationandroid:icon="@mipmap/ic_launcher"android:label= "@string/app_name"> <!--first activity--> <activity android:name=". Mainactivity "> <intent-filter> <action android:name="Android.intent.action.MAIN" /> <category android:name="Android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!--a second activity--> <activity android:name=". Alertactivity "android:theme=" @android: Style/theme.dialog "> </activity> </Application></manifest>
5.2 Activity Tags Common Properties
The activity tag also has some of the properties that we commonly use.
The intent-filter
content specified in the tag here indicates: This activity can be used as an entry point for this application.
< Activity android:name = ". Mainactivity "; <!--Specify application entry--> intent-filter ; < action android:name = "Android.intent.action.MAIN" / <category Android:name = "Android.intent.category.LAUNCHER" /> </intent-filter ; </activity ;
The intuitive point is that it can be placed on the desktop for the user to enter directly by clicking. If an application has three such activity, then there will be three icons on the desktop for the user to click to start.
Specifies the subject of the activity. The Android system designs several different display styles for the interface elements, called themes. For a detailed introduction of the topic we will put it in a later chapter.
<activity android:name=".AlertActivity" <!--指定Activity的主题--> android:theme="@android:style/Theme.Dialog"></activity>
-
Specifies how activity is started. The startup method is described in detail in the next section.
< Activity android:name = ". Alertactivity " <! -- Specifies the startup mode of activity --; android:launchmode= "standard" ></ activity ;
Specifies whether activity is concerned with changes in system configuration,
<activity android:name=".AlertActivity" <!--指定Activity关注的系统变化类型,这里只表示关注屏幕大小是否变化-screenSize、设备方向是否变化-orientation--> android:configChanges="screenSize|orientation"></activity>
Response-specific Action
, Action
you can start the activity if you encounter such a
<activity android:name=".VideoPlayer"> <intent-filter> <action android:name="android.intent.action.VIEW" /> </intent-filter></activity>
Then, the code that launches the activity can be configured in it Action
,
new Intent("android.intent.action.VIEW");startActivity(i);
In addition to some of the properties listed above, there are many features of activity that can be set.
Section 6th Activity Start mode
The activation mode of activity refers to how the activity is managed in a task when the user or system initiates an activity.
<activity android:name=".AlertActivity" <!--指定Activity的启动模式--> android:launchMode="standard"></activity>
Activity has four ways to start: Standard, Singletop, Singletask, SingleInstance.
6.1 Standard Mode
This is the default startup mode for each activity, and if we do not specify it in manifest, then the activity will start with this mode. This pattern is simple and has only one principle: When you start this type of activity, just recreate it and put it on top of the stack of the task stack.
A further example: on activity A, there is a button that, when clicked, can then start an activity a. At this point we see the task stack, where activity A is created. These two activity are instances of activity A, are independent of each other activity, in memory have their own piece of area.
6.2 Singletop Mode
The principle of this startup mode is: When initiating this type of activity, if the activity has an instance in the current task and is located at the top of the task, then call Onnewintent () to notify, instead of recreating;
Otherwise, even if there is an activity instance in the task, it is recreated as long as it is not at the top of the stack;
Usage Scenario: A news client receives a news feed and shows that it has received 10 tweets on StatusBar. When we click on the first one, we start a activity-contentactivity that shows the news content, and when we click on the second news on StatusBar, we start contentactivity again. If contentactivity is Standard mode, you can imagine, in the previous news content, back to pop up a activity,10 bar push click 10 times, there will be 10 activity stacked together.
The trouble is that you have to press 10 times when you return, and you will consume a lot of system resources.
If contentactivity is specified as Singletop, then when you click on the next 9 pushes, contentactivity will only know that there is a new call request through Onnewintent (), and you do not have to recreate 9 activity instances to consume resources unnecessarily.
6.3 Singletask Mode
The principle of this startup mode is: When starting this type of activity, see if there are instances of the activity that exist in the system's current task.
6.3.1 presence in the foreground task
If it exists in a task in the foreground and is at the top of the task's stack, then the call is onNewIntent()
notified instead of being recreated-this is similar to the singletop pattern;
If it exists, but not on the top of the task, it pops up all of the activity's activity, destroys it, puts the activity's instance on top, and onNewIntent()
notifies it once.
6.3.2 The background task exists
If it exists in a task that is in the background, the background task is placed in the foreground, and then the other activity that exists above it is ejected and destroyed.
Usage Scenario: The application's main activity A, can start activity B, activity B can also start activity c,c and can start D, the designer wants to be able to return from D directly to the main activity.
For this kind of hope at any level of activity, quickly return to the main interface of the application, you can set the main activity a to Singletask mode.
6.4 SingleInstance Mode
The principle of this startup mode is that when this type of activity is started, if the activity does not exist before it, a task is recreated and the activity is put into it. If the activity is to start another activity-c, then put it on top of the previous task.
If the activity already exists, switch the task where the activity is located to the foreground.
In summary, there is only one activity of this type in a task.
Usage Scenario: This activity can be set to singgleinstance for activity that needs to be made available to third-party calls, such as sharing and forwarding. This ensures that only one such activity exists within the system scope.
7th section of the ADB tool commissioning activity
To help us learn more about activity, here's how to get information about existing activity in your system through the ADB tool.
7.1 Printing System Activity information
Use the command line tool to enter the directory where ADB is located,
Input adb shell dumpsys activity activities
, it will output something like the following:
$./ADB Shell Dumpsys activity activitiesactivity MANAGER Activities (Dumpsys activity activities) Display#0 (activities from top to bottom):Stack#0:Task ID#178* taskrecord{cce8184#178 i=com.android.launcher3/. Launcher u=0 Sz=1}Userid=0EFFECTIVEUID=U0A8 mcallinguid=0Mcallingpackage=null intent={act=android. Intent. Action. MAINCat=[android. Intent. Category. HOME] Flg=0x10000000cmp=com. Android. Launcher3/. Launcher} realactivity=com. Android. Launcher3/. LauncherAutoremoverecents=false ispersistable=true numfullscreen=1Tasktype=1mtasktoreturnto=0Rootwasreset=false mneverrelinquishidentity=true mreusetask=false mlocktaskauth=lock_task_auth_pinnable Activities =[activityrecord{b820c49 u0com. Android. Launcher3/. Launchert178}] askedcompatmode=false inrecents=true isavailable=true lastthumbnail=null lastthumbnailfile=/data/system/r ecent_images/178_task_thumbnail. PNGStackid=0Hasbeenvisible=true Mresizeable=false firstactivetime=1451983947131Lastactivetime=1451983947131(Inactive for2501s) * Hist#0: activityrecord{b820c49 u0 com.android.launcher3/. Launcher t178}Packagename=com. Android. Launcher3 processname=com. Android. Launcher3 launchedfromuid=0Launchedfrompackage=null userid=0app=processrecord{f7b8d6d25040:com. Android. Launcher3/U0A8} Intent {act=android. Intent. Action. MAINCat=[android. Intent. Category. HOME] Flg=0x10000000cmp=com. Android. Launcher3/. Launcher} frontoftask=true task=taskrecord{cce8184#178 i=com.android.launcher3/. Launcher u=0 Sz=1}Taskaffinity=null realactivity=com. Android. Launcher3/. LauncherBasedir=/system/priv-app/launcher3/launcher3. apkdatadir=/data/user/0/com. Android. Launcher3 Statenotneeded=true Componentspecified=false mactivitytype=1compat={420DPI} labelres=0x7f0c0005icon=0x7f030000Theme=0x7f0e000econfig={1.0 310MCC260MNC zh_cn ldltr SW411DP W411DP H659DP420DPI nrml Port finger qwerty/v/v dpad/v S. 6} stackconfigoverride={1.0Mcc?mnc? locale Layoutdir? SWDP WDP? HDP? density? lsize? orien? uimode? night?? keyb/?/? Taskdescription:iconfilename=null label="NULL"color=ff212121 Launchfailed=false launchcount=1lastlaunchtime=- AM41s66ms havestate=false icicle=null state=resumed stopped=false delayedresume=false finishing=false Keyspaused=false inhistory=true visible=true sleeping=false idle=true fullscreen=true noDisplay=false immer Sive=false launchmode=2Frozenbeforedestroy=false Forcenewconfig=false Mactivitytype=home_activity_type WaitingVisible=false now Visible=true lastvisibletime=- AM39s31ms Running Activities (most recent first): taskrecord{cce8184#178 i=com.android.launcher3/. Launcher u=0 Sz=1}Run#0: activityrecord{b820c49 u0 com.android.launcher3/. Launcher t178}Mresumedactivity:activityrecord{b820c49 u0com. Android. Launcher3/. Launchert178} mfocusedactivity:activityrecord{b820c49 u0com. Android. Launcher3/. Launchert178} mfocusedstack=activitystack{c009da2 stackid=0,1Tasks} mlastfocusedstack=activitystack{c009da2 stackid=0,1Tasks} msleeptimeout=false mcurtaskid=178muserstackinfront={} mactivitycontainers={0=activtycontainer{0}a} mlocktaskmodestate=none mlocktaskpackages (userid:packages) =0: [] mlocktaskmodetasks[]
It records all the tasks in the current Android system and the activity information contained in each task.
For example, here's the record,
- There is one in
Task id
#178
the system Task
;
Task
The activity in the stack, from top to bottom TaskRecord---com.android.launcher3/.Launcher
, is one Activity
;
- And
com.android.launcher3/.Launcher
This Activity
is located at the front desk Activity
;
This information will be of great help to the debugging of the program.
7.2 adb start activity
Start known activity with the ADB tool,
$ ./adb shell am start -n 包名/包名.activity名称}
Here the package name is like: Com.android.launcher3, for example
com.android.launcher3/com.android.launcher3.Launcher}
Activity of four components (under)--activity Common manifest Properties, startup mode, ADB debug