Androidmanifest. xml file (2)

Source: Internet
Author: User

Conventions

Some conventions and rules generally apply to all elements and attributes in the list:

Element

Only <manifest> and <Application> elements are required, and the two elements can only appear once in the file. Other elements can appear in the list multiple times, or do not appear at all-but to build a meaningful list, some elements must be declared in the list.

Any declaration contained in an element, including other elements contained in it, all values are set through attributes, rather than character data clipped between open and closed elements.

Elements of the same level usually have no order. For example, the <activity>, <provider>, and <service> elements can be in any order. (The <activity-alias> element is an exception and must be placed behind the <activity> element it represents .)

Attribute

In the formal meaning, all attributes are optional. However, to achieve the purpose, you must specify some attributes for the element. For real optional properties, the default value or status will be specified in special circumstances.

Except for some attributes of the <manifest> root element, all attributes are named with the Android: prefix --- for example, Android: alwaysretaintaskstate. Because this prefix is generic, This prefix is usually ignored when this document mentions an attribute name.

Declared Class Name

Many elements correspond to Java objects, including elements that represent the application <Application>, and basic components --- <activity>, <service>, <consumer ER>, and <provider>.

To define subclasses, these subclasses almost always inherit from the following component classes: Activity, service, broadcastreceiver, and contentprovider. Subclass is declared through the name attribute. This name must be the complete Java package name. For example, the following example shows how to declare a service subclass:

<Manifest...
>
<Application...
>
<Service
Android: Name = "com. example. Project. secretservice "...
>
...
</Service>
...
</Application>
</Manifest>

However, you can also use the "." symbol as the first character of the name attribute value. In the Android system, the package name is appended before the "." symbol (the package name is declared in the package attribute of the <manifest> element ). The declaration method in the following example is the same as that in the previous example:

<Manifest
Package = "com. example. Project "...
>
<Application...
>
<Service
Android: Name = ". secretservice "...
>
...
</Service>
...
</Application>
</Manifest>

When a component is started, Android creates an instance object for this subclass. If no subclass is specified, a base class instance object is created.

Set multiple values

If you want to specify multiple values for an element, this element is almost always used repeatedly, rather than listing multiple values in an element. For example:

<Intent-filter...
>
<Actionandroid: Name = "android. Intent. Action. Edit"/>
<Actionandroid: Name = "android. Intent. Action. Insert"/>
<Actionandroid: Name = "android. Intent. Action. Delete"/>
...
</Intent-filter>

Resource Value Setting

Some attribute values can be displayed to users-for example, the title and icon of the activity. These attribute values should be localized and therefore set to resources or topics. The resource value is expressed in the following format :@[Package:]Type:Name

If the resource and application are in the same package, the package name can be ignored. type is the type of the resource, for example, "string" or "drawable ", name indicates the name of the specified resource. For example:

<Activity
Android: icon = "@ drawable/smallpic "...
>

The value from the topic is expressed in a similar way, but it must be '? 'Start, not '@':

? [Package:]Type:Name

Set the string value

When the attribute value is a string, the '\' symbol must be used for character escaping. For example, '\ n' indicates a line break here, '\ uxxxx' indicates that 'xxx' is a Unicode character.

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.