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

Android Development Notes-4(BroadcastReceiver, Manifests)

2016-06-22 23:15 387 查看
Summary: BroadcastReceiver, Manifests, Delvik VM, Zigote, Life Cycle, apk

-A broadcast receiver receives the action of  Intent objects, similarly to an  Activity , but does not have its own user interface

-A typical use for a broadcast receiver might be to receive an alarm that causes an app to become active at a particular time

-Android requires applications to explicitly describe their contents in an XML file called AndroidManifest.xml

-Activity ,  Service , ContentProvider , and  BroadcastReceiver provide the foundation of Android application development . To make use of any of them, an application must include corresponding declarations in its AndroidManifest.xml file.



AndroidManifest.xml sample:

res/

layout/

... contains application layout files ...

drawable/

...contains images, patches, drawable xml ...

raw/

... contains data files that can be loaded as streams ...

values/

... contains xml files that contain string, number values used in code ...

src/

java/package/directories/

-Android executes multiple instances of the Dalvik VM, one for each task

-Android must efficiently divide memory into multiple heaps. Each heap should be relatively small so that many applications can fit in memory at the same time. 

-Android’s approach to multiprocessing, using multiple processes and multiple instances of a VM, requires that each instance of the VM be space-efficient. This is achieved

partly through the component life cycle, which enables objects to be garbage-collected and recreated, and partly by the VM itself.

-Zygote. It is an instance of the Dalvik VM that contains a set of preloaded classes for enhancement of performance.

-The most complex component life cycle is the activity life cycle. Here we will diagram it and take a look at how these state transitions are handled in code



-Sample code:

@Override
protected void onSaveInstanceState(Bundle outState) {
// Save instance-specific state
outState.putString("answer", state);
super.onSaveInstanceState(outState);
Log.i(TAG, "onSaveInstanceState");
}
@Override
protected void onRestoreInstanceState(Bundle savedState) {
super.onRestoreInstanceState(savedState);
// Restore state; we know savedState is not null
String answer = savedState.getString("answer");
// ...
Log.i(TAG, "onRestoreInstanceState"
+ (null == savedState ? "" : RESTORE) + " " + answer);
}
-In a lot of Android code, especially in small examples, very few life cycle callbacks are implemented. That is because the  Activity parent class handles life cycle callbacks

-Android provides an application called  apkbuilder for generating installable Android application files, which have the extension .apk. An .apk file is in ZIP file format

Author:Joey_Zhang
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息