Post date: Jul 23, 2009 7:34:5 AM
Ref URL:http://developer.android.com/guide/topics/fundamentals.html
Android的4种componet
Activities:
标准应用程序
带UI界面
窗口可以是全屏的,也可以浮动在别的窗口上面。
View类应该是一个容器,放置各种UI组件,如按钮,文本框,菜单等等
see also:Activity的生命周期
Services:
后台运新的程序
无UI
继承 Service
比如媒体播放器,UI界面是Activities,后台播放音乐的就是一个Services
单独线程,不干扰其他界面
Broadcast reveivers:
是一个component
接收系统的各种消息:
时区切换
电力低
。。。
可以打开一个Activities,使用 NotificationManager来通知用户。
Content providers:
用于和别的应用交换数据
数据可以存为文本,存在SQLite数据库等等地方
这个类提供一组retrieve和stroe数据的方法
别的应用不能直接使用这些方法,必须通过 ContentResolver来访问
Componets的激活方式
Content provider由ContentResolver来激活
其它3种componet都是通一个叫Intent的东西来激活的
intent是一种异步的消息
可以携带数据,用于Activities返回的数据
相关函数调用
Context.startActivity() or Activity.startActivityForResult().
getIntent(),activity's onNewIntent(),
startActivityForResult(), activity's onActivityResult()
service's onStart()
Context.sendBroadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast()
结束components
交换数据和广播接收的component因为是特定条件下启动的,同样处理完了就可以结束了,所以不需要额外的结束这些componets。
Activeity
call finish()
结束别的activeity by calling finishActivity().
Service
定义component:manifest file
叫AndroidManifest.xml
(to be continue...)