您的位置:首页 > 移动开发 > Android开发

Android 开发文档 程序基础——The manifest file

2010-06-19 10:52 393 查看
android开始运行一个程序组件之前,会先确定这个组件的存在。因此,程序会在打包在apk中的manifest文件中声明组件,apk文
件中同时也有代码,文件和资源。

manifest是xml文件,在所有的程序中都命名为AndroidManifest.xml。除了声明程序组件之外,还做一些其他的事情,例如
命名程序需要链接的库,确认程序希望被授予的权限。

不过最主要的任务还是告诉android有关程序的组件。例如:

<?xml version=”1.0″
encoding=”utf-8″?>

<manifest . . . >

<application . . . >

<activity android:name=”com.example.project.FreneticActivity”

android:icon=”@drawable/small_pic.png”

android:label=”@string/freneticLabel”

. . . >

</activity>

. . .

</application>

</manifest>

没有在manifest文件中声明的组件在系统中不可见,因此
也不会运行。但是broadcast
receiver不但可以在manifest中声明,也可以在代码中动态创建,通过调用Context.registerReceiver()来注册到系
统中。

转自我的android博客

原文

The manifest file

Before Android can start an application component, it must learn
that the component exists. Therefore, applications declare their
components in a manifest file that’s bundled into the Android package,
the .apk
file that also
holds the application’s code, files, and resources.

The manifest is a structured XML file and is always named
AndroidManifest.xml for all applications. It does a number of things in
addition to declaring the application’s components, such as naming any
libraries the application needs to be linked against (besides the
default Android library) and identifying any permissions the application
expects to be granted.

But the principal task of the manifest is to inform Android about
the application’s components. For example, an activity might be
declared as follows:

<?xml version=”1.0″
encoding=”utf-8″?>

<manifest . . . >

<application . . . >

<activity android:name=”com.example.project.FreneticActivity”

android:icon=”@drawable/small_pic.png”

android:label=”@string/freneticLabel”

. . . >

</activity>

. . .

</application>

</manifest>

The name
attribute of
the <activity>

element names the Activity
subclass that implements the activity. The icon
and label
attributes point to resource files containing an icon and label that
can be displayed to users to represent the activity.

The other components are declared in a similar way — <service>
elements for
services, <receiver>
elements for broadcast receivers, and <provider>
elements for content providers.
Activities, services, and content providers that are not declared in
the manifest are not visible to the system and are consequently never
run. However, broadcast receivers can either be declared in the
manifest, or they can be created dynamically in code (as BroadcastReceiver
objects) and
registered with the system by calling Context.registerReceiver()
.

For more on how to structure a manifest file for your application,
see The AndroidManifest.xml File.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: