Learn about the basics of Android from 0 (2)-Explanation of the AndroidMainfest. xml file

Source: Internet
Author: User

Learn about the basics of Android from 0 (2)-Explanation of the AndroidMainfest. xml file
AndroidMainfest. xml file details

1. About AndroidManifest. xml

AndroidManifest. xml is a required file in every android program. It is located in the root directory of the entire project, describing components exposed in the package (activities, services, and so on), their respective implementation classes, various data that can be processed and startup locations. In addition to declaring Activities, ContentProviders, Services, and Intent Receivers in the program, you can also specify permissions and instrumentation (Security Control and testing)

It is located on the java folder in the directory, as shown in:

 

When creating a new project, the system sets some properties for our AndroidManifest. xml file by default, such:

 

 

II,AndroidManifest. xml structure

 
                         
                                  
               
   
                              
              
                                   
                    
                 
    
           
  
          
                   
                
                 
       
        
       
      
     
    
            
                 
       
        
         
          
        
        
      
     
             
       
        
         
          
        
        
              
       
      
     
    
   
  
  
   
    
         
       
        
       
          
       
        
         
          
           
            
             
              
               
                
                 
                  
                   
                   
                  
                 
                
               
              
             
            
           
          
         
        
       
      
     
    
   
  
 

III,Introduction to each node

The above is the structure of the entire am (androidManifest). xml, which will be described in the following step ~~

1. The first layer ( ) :( Attribute)

 

     


 

 

A. xmlns: android

Defines the android namespace, which is generally named.

B revisionCode

Android: revisionCode indicates the version number of the software, which is visible to users. It must be an integer of the int type. Its size indicates how many times the software version has been upgraded, therefore, this value is + 1 each time a new version is released. For example, Android: versionCode = "5" indicates that the software has been released five times.


C. package

Specifies the package name of the main java package in the application. It is also the default name of an application process.


D. sharedUserId

Indicates the data permission. By default, Android assigns a unique UserID to each APK, so different APK access to shared data is prohibited by default. To Share data, you can first use the Share Preference method, and then use sharedUserId to set the sharedUserId of different APK files to the same, then these apks can share data with each other. See: http://wallage.blog.163.com/blog/static/17389624201011010539408/

E. sharedUserLabel

A shared user name that makes sense only when the sharedUserId attribute is set.


F. versionCode

An interger value must be used to identify the version (upgrade) of a device program. For example, the first version is generally 1, to update the version, set it to 2, 3, and so on...


G, versionName

This name is for users. You can set your APP version to version 1.1 and later versions to version 1.2 and 2.0...


H. installLocation

The installation parameter is a new feature in Android2.2. installLocation has three values: internalOnly, auto, and preferExternal.

If preferExternal is selected, the system first installs the APK on the SD card (of course, the end user can choose the internal ROM storage. If the SD storage is full, it will also be installed on the internal storage)

When auto is selected, the system will adapt according to the storage space

When internalOnly is selected, it must be installed internally to run

(Note: it is best to install apps that require background monitoring, while some large game apps should be installed on SD cards. By default, the APP is installed internally. If you install the APP on the SD card, you must first set your level to 8 and set the property of android: installLocation to preferExternal)


2. Layer 2 (): attribute

An AndroidManifest. xml must contain an Application tag, which declares the components and attributes (such as icon, label, and permission) of each Application)

 

 

 

 

A. android: allowClearUserData ('true' or 'false ')

Whether the user can manually clear data. The default value is true. The Program Manager contains an option that allows the user to clear data. If this parameter is set to true, you can clear user data by yourself, and vice versa.


B. android: allowTaskReparenting ('true' or 'false ')

Whether to allow the activity to change the subordinate task, such as switching from a short message task to a browser task


C. android: backupAgent

This is also a new feature in Android2.2. When setting backup for this APP, the attribute value should be a complete class name, such as com. project. testCase, this property does not have a default value, and the class name must be specified (it is a backup tool that backs up data to the cloud)


D. android: debuggable

This can be seen from the literal meaning. When it is set to true, it indicates that the APP can be debugged on the mobile phone. The default value is false. If it is false, the following error is reported when the APP is debugged:

Device XXX requires that applications explicitely declare themselves as debuggable in their manifest.

Application XXX does not have the attribute 'destggable' set to TRUE in its manifest and cannot be debugged.


E. android: description/android: label

Both attributes are licensed and are string resources. When you view the license list (android: label) or details of a license (android: description, these string resources can be displayed to the user. The label should be as short as possible, so you need to inform the user of the function that the license is protecting. Description can be used to describe what the program that obtains the permission can do. In fact, it allows users to know what the program can do if they agree to obtain the permission. We usually use two sentences to describe the license. The first sentence is to describe the license, and the second sentence is to warn the user of any bad things if they approve the permission.


F. android: enabled

Whether the Android system can instantiate the component of the application. If the value is true, the enabled attribute of each component determines whether the component can be enabled. If it is false, it overwrites the specified value of the component; all components are disabled.


G. android: hasCode ('true' or 'false ')

Indicates whether the APP contains any code. The default value is true. If the value is false, the system will not try to load any APP code when running components.

An application itself does not contain any code unless the built-in component class, such as the Activity class, uses the AliasActivity class, which of course is a rare phenomenon.

(In Android2.3, you can use standard C to develop applications. You can set this attribute to false in androidManifest. xml because the APP itself does not contain any JAVA code)

H. android: icon

This is very simple. It is to declare the icon of the entire APP. images are usually placed in the drawable folder.

I. android: killAfterRestore

J. android: manageSpaceActivity

K. android: name

The full name of the Application subclass implemented by the Application. When an application process starts, the class is instantiated before all application components.

If the class (such as the androidMain class) is under the declared package, you can directly declare android: name = "androidMain", but this class is a sub-package under the package, the package name must be declared as full path or android: name = "package name. sub-package name. androidMain"

L. android: permission

Set the license name. If this property is defined above, it is a convenient way to permit all components of the application. Of course, it is overwritten by the license name set by each component.

M, android: presistent

Whether the application should be running at any time. The default value is false. Because applications generally do not need to set this identifier, continuous mode should only be set to some system applications.

N. android: process

The name of the process where the application is running. Its default value is The package name set in the element. Of course, each component can overwrite the default value by setting this attribute. If you want two applications to share a process, you can set their android: process to be the same, but only if they share a user ID and are granted the same certificate

O, android: restoreAnyVersion

It is also a new feature of android2.2, which is used to indicate whether the application is trying to recover all the backups, or even whether the backup is a newer version than the current device. The default value is false.

P. android: taskAffinity

In theory, an Activity with the same affinity belongs to the same Task. The default affinity of an application is Package name set in element


Q. android: theme

It is a resource style. It defines a default theme style for all activities. Of course, you can also set it in your own theme, which is similar to the style.

3. Layer 3 (): attribute

 

   

 

 

 

 

(Note: I will not elaborate on some repeated applications)

1. android: alwaysRetainTaskState

Whether to keep the status unchanged. For example, if you switch back to home and open the activity again, the activity is in the final state. For example, if a browser has many statuses (when multiple tabs are opened) and you do not want to lose these statuses, you can set this attribute to true.

2. android: clearTaskOnLaunch
For example, if P is activity, Q is activity triggered by P, return Home, restart P, and check whether Q is displayed.

3. android: configChanges

When the configuration list is modified, whether to call the onConfigurationChanged () method, for example, "locale | navigation | orientation ".
I have used this to check that the direction of the mobile phone is changed. After the android phone is rotated, layout will be laid out again. How can this problem be solved?
Under normal circumstances, if the mobile phone is rotated, the current Activity is killed, and the Activity is re-loaded in the direction, it will be re-loaded from onCreate.
If you set this option, after the mobile phone is rotated, the onConfigurationChanged () method is called after the current Activity, instead of running the onCreate method.

4. android: excludeFromRecents

Whether it can be displayed in the list of recently opened activities. The default value is false.

5. android: finishOnTaskLaunch

When you restart the task, whether to disable the opened activity. The default value is false.

If both this attribute and allowTaskReparenting are true, this attribute is the trump card. Activity affinity will be ignored. This Activity has been destroyed, not re-parented.


6. android: launchMode (Activity Loading Mode)

In multi-Activity development, Activity jumps between applications or reusable activities with other applications. You may want to jump to an existing Activity instance instead of generating a large number of duplicate activities. This requires configuring a specific loading mode for the Activity, instead of using the default loading mode.

Activity has four loading modes:

Standard, singleTop, singleTask, and singleInstance (the first two are one group, and the last two are one group). The default value is standard.

Standard: intent will be sent to a new instance, so a new activity will be generated every time you jump.

SingleTop: it also sends new instances, but the difference between the standard is that when the requested Activity is located at the top of the stack (configured as the singleTop Activity), no new instances will be constructed.

SingleTask: only one instance is created for singleInstance and later instances. When intent arrives and an Activity set to singleTask needs to be created, the system checks whether there are instances of this Activity in the stack. If any, send intent directly to it.

SingleInstance:

First, describe the concept of task. A Task can be considered as a stack and put into multiple activities. For example, if you start an application, Android creates a Task and starts the entry Activity of the application. Other activities called on its interface are only in this task. What should I do if I share an Activity among multiple tasks. For example, if you open a tour guide service application, there is an Activity that enables GOOGLE map. When you press the home Key to return to the main menu and start the GOOGLE map application, the map is displayed. It is actually the same Activity. In fact, singleInstance is introduced. The singleInstance mode puts the Activity into a single stack. In this way, only this Activity is in the stack, and intent of different applications are received and displayed by this Activity, so that sharing is achieved. Of course, the premise is that these applications are not destroyed, so the HOME Key is pressed just now. If the return key is pressed, the result is invalid.

7. android: multiprocess

Whether to allow multiple processes. The default value is false.

Specific can see this article: http://www.bangchui.org/simple? T3181.html

8. android: noHistory

When the user leaves the Activity and it is no longer visible on the screen, whether the Activity is cleared and ended from the Activity stack. The default value is false. Activity does not leave traces of History

9. android: screenOrientation

Activity Display Mode

The default value is unspecified. The system automatically determines the display direction.

Landscape mode, with a larger width than the height

Portrait Screen mode, height greater than width

User mode, the user's current preferred direction

Behind mode: consistent with the direction of the Activity under the Activity (in the Activity stack)

Sensor mode: determined by physical sensors. If you rotate the device, the screen will be switched horizontally and vertically.

Nosensor mode: Ignore the physical sensor so that it will not change as the user rotates the device

10. android: stateNotNeeded

Whether the activity is saved when it is destroyed or restarted successfully

11. android: windowSoftInputMode

The interaction mode between the activity main window and the soft keyboard can be used to avoid the problem of blocking the input method panel. This is a new feature after Android1.5.

This attribute can affect two things:

[A] whether the keyboard is hidden or displayed when the focus is generated

[B] whether to reduce the size of the active main window to free up space and put it on the keyboard

Meanings of values:

[A] stateUnspecified: the soft keyboard status is not specified. The system selects an appropriate status or depends on the topic settings.

[B] stateUnchanged: When this activity appears, the soft keyboard will remain in the status of the previous activity, whether hidden or displayed.

[C] stateHidden: When you select activity, the keyboard is always hidden.

[D] stateAlwaysHidden: when the Activity's Main Window gets the focus, the keyboard is always hidden.

[E] stateVisible: the soft keyboard is usually visible.

[F] stateAlwaysVisible: when the activity is selected, the soft keyboard always displays the status

[G] adjustUnspecified: the default setting. It is usually determined by the system whether to hide or display it.

[H] adjustResize: This Activity always adjusts the screen size to reserve space for the soft keyboard.

[I] adjustPan: the content in the current window will be automatically moved so that the current focus is not overwritten by the keyboard and the user can always see the input content.

4. Layer 4 ( )

Structure:

Android: label = "string resource"
Android: priority = "integer">

 

Intent-filter attributes

Android: priority (explanation: ordered Broadcast mainly follows the declared priority level. For example, if the level is higher than B, broadcast is first transmitted to A and then to B. The priority level is determined by setting the priority attribute. The range is from-1000 ~ 1000, the higher the number, the higher the priority)


The information set in the Intent filter includes action, data, and category. That is to say, the filter will only compare with the three types of data in intent.


Action property

Action is simple. Only the property android: name is used. The common android: name value is android. intent. action. MAIN, indicating that this activity is used as the portal of the application. For android: name specific value, refer to this URL: http://hi.baidu.com/linghtway/blog/item/83713cc1c2d053170ff477a7.html

Category attributes

Category only has the android: name attribute. Common android: the value of name is android. intent. category. LAUNCHER (determines whether the application is displayed in the program list)

For android: name specific value, refer to this URL: http://chroya.javaeye.com/blog/685871

Data attributes

Android: mimeType = "string"
Android: path = "string"
Android: pathPattern = "string"
Android: pathPrefix = "string"
Android: port = "string"
Android: scheme = "string"/>

[1] EachThe element specifies a URI and data type (MIME type ). It has four attributes: scheme, host, port, and path, which correspond to each part of the URI:
Scheme: // host: port/path

The value of scheme is generally "http", the host is the package name, the port is the port number, and the path is the specific address. For example: http://com.test.project: 200/folder/etc

The host and port constitute the URI credenity (authority). If the host is not specified, the port is ignored.

To make the authority meaningful, scheme must also be specified. To make the path meaningful, scheme + authority must also be specified

[2] mimeType (specify the Data Type). If mimeType is 'image', the data of the Image type is obtained from the specified address of the content Provider. What about 'video'? If it is set to video/mp4, the video file in mp4 format is obtained from the specified address.

[3] pathPattern and PathPrefix are mainly used to format

5. Layer 4

Android: resource = "resource specification"
Android: value = "string"/>

This is the basic structure of the element. It can be included in Of the four elements.

Android: name (explanation: Metadata item name. To ensure that this name is unique, java-style naming rules are adopted, such as com. woody. project. fried)

Android: resource (explanation: a reference to a resource. The value specified for this item is the id of the resource. This id can be found in meta-data through Bundle. getInt .)

Android: value (explanation: the value specified for this item. Bundle methods that can be specified as values and used by components to retrieve those values: [getString], [getInt], [getFloat], [getString], [getBoolean])


6. layer-3 attributes

Android: exported = ["true" | "false"]
Android: icon = "drawable resource"
Android: label = "string resource"
Android: name = "string"
Android: permission = "string"
Android: targetActivity = "string">


Is to create a shortcut for the activity, as shown in the following example:


 

 

 

 

Specifically, android.tar getActivity points to the activity of the corresponding shortcut, as shown in the previous example (this Activity name)

Android: label refers to the shortcut name, And the shortcut icon is the specified application icon by default.


7. Layer 3

[1] The service and activity are at the same level. Different from the activity, the Service cannot be started by itself and runs in the background program. If the service process does not end when we exit the application, it is still running in the background. For example, listening to music and downloading data over the Internet are all run by the service.

[2] service lifecycle: the Service only inherits the onCreate (), onStart (), and onDestroy () methods. when the Service is started for the first time, onCreate () is called successively (), onStart (): when the Service is stopped, the onDestroy () method is executed. if the Service has been started, the onCreate () method is not executed when the Service is started again, instead, execute the onStart () method directly.

[3] communication between service and activity

The data at the backend of the Service must be displayed on the front-end Activity, because when the Service is started, the system restarts a new process, this involves communication between different processes (AIDL). The communication between Activity and service is mainly handled by IBinder. See: http://zhangyan1158.blog.51cto.com/2487362/491358

[4]

Android: exported [= "true" | "false"]

Android: icon = "drawable resource"

Android: label = "string resource"

Android: name = "string"

Android: permission = "string"

Android: process = "string">

 

The attribute in the service tag has already been described and is not repeated here ~

8. Layer 3

The attributes of the consumer er are the same as those of the service.

BroadcastReceiver: used to send broadcast, Broadcast is a mechanism for transmitting information between applications, while BroadcastReceiver is a class of component for filtering and receiving and responding to the broadcast sent by referring to the http://kevin2562.javaeye.com/blog/686787

9. Layer 3 Attribute

Android: enabled = ["true" | "false"]

Android: exported = ["true" | "false"]

Android: grantUriPermissions = ["true" | "false"]

Android: icon = "drawable resource"

Android: initOrder = "integer"

Android: label = "string resource"

Android: multiprocess = ["true" | "false"]

Android: name = "string"

Android: permission = "string"

Android: process = "string"

Android: readPermission = "string"

Android: syncable = ["true" | "false"]

Android: writePermission = "string">

 

ContentProvider (Data Storage)

[1] android: authorities:

Identifies the ContentProvider, which can be found by the caller.

[2] android: grantUriPermission:

Permission granted to a URI

[3] android: initOrder

10. Layer 3

User library, which can be customized. All android packages can be referenced

11. Layer 1

Android: normalScreens = ["true" | "false"]
Android: largeScreens = ["true" | "false"]
Android: anyDensity = ["true" | "false"]/>

This is a new feature after android1.6 and supports multi-screen mechanism.

Meaning of each attribute: whether the four attributes support large screen, medium screen, small screen, and different density

12. Layer 2 And Performance is similar

Android: reqHardKeyboard = ["true" | "false"]
Android: reqKeyboardType = ["undefined" | "nokeys" | "qwerty" | "twelvekey"]
Android: reqNavigation = ["undefined" | "nonav" | "dpad" | "trackball" | "wheel"]
Android: reqTouchScreen = ["undefined" | "notouch" | "stylus" | "finger"]/>

Android: name = "string"
Android: required = ["true" | "false"]/>

Both of them describe the hardware and software features required by the application to Prevent the application from being installed on devices without these features.


13. Layer 2

Android: targetSdkVersion = "integer"
Android: maxSdkVersion = "integer"/>

The api level required to describe the application, that is, the version. Currently it is android 2.2 = 8, android2.1 = 7, android1.6 = 4, android1.5 = 3

You can specify the supported minimum version, target version, and maximum version in this attribute.

14. Layer 2

Android: handleProfiling = ["true" | "false"]
Android: icon = "drawable resource"
Android: label = "string resource"
Android: name = "string"
Android: targetPackage = "string"/>

Defines some classes used to detect and analyze application performance and so on, and can monitor programs. The instrumentation class is instantiated before components of each application

Android: functionalTest (explanation: whether the instrumentation class can run a function test. The default value is false)

15, , , , Differences ~

The most common genus When we need to obtain a permission, we must declare it in our manifest file. Similar to the same level. For details about the permission list, see here

Generally, you do not need to declare a permission for your application unless you provide the code or data that can be called by other applications. You need to use This label. Obviously, this tag allows us to declare our permissions. For example:

You can declare the custom permission in the activity, for example:


Android: permission = "com. teleca. project. MY_SECURITY">

 

Of course, the declared permission cannot be used at will. To declare that you need this permission

Is to declare a tag, which represents a group of permissions, and Declares a namespace for a group of permissions. These two labels can be viewed in the previous series of articles.

 

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.