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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值