Android ApiDemos示例解析(43):App->Service->Remote Service Controller
来源:互联网 发布:c语言sleep 编辑:程序博客网 时间:2024/05/21 16:53
Remote Service Controller 和使用Local Service的Android ApiDemo示例解析(40):App->Service->Local Service Controller
都是使用Service的“Started” 模式,RemoteService在 AndroidManifest.xml中的定义如下:
<service android:name=”.app.RemoteService” android:process=”:remote”>
<intent-filter>
< !– These are the interfaces supported by the service, which
you can bind to. –>
<action android:name=”com.example.android.apis.app.IRemoteService” />
<action android:name=”com.example.android.apis.app.ISecondary” />
< !– This is an action code you can use to select the service
without explicitly supplying the implementation class. –>
<action android:name=”com.example.android.apis.app.REMOTE_SERVICE” />
< /intent-filter>
< /service>
RemoteService.Controller 中启动和停止Service的代码如下,和“Bound” Service模式相比要简单的多:
// Make sure the service is started. It will continue running// until someone calls stopService().// We use an action code here, instead of explictly supplying// the component name, so that other packages can replace// the service.startService(new Intent( "com.example.android.apis.app.REMOTE_SERVICE")); ... ... // Cancel a previous call to startService(). Note that the// service will not actually stop at this point if there are// still bound clients.stopService(new Intent( "com.example.android.apis.app.REMOTE_SERVICE"));
“Started” Service在启动之后会一直运行,直到调用stopService为止。因此在按“Start Service”后,在运行Android ApiDemo示例解析(42):App->Service->Remote Service Binding 来绑定这个RemoteService,由于RemoteService已经启动,你会发现例42中的Received from Service的初始值一般不会为1。
- Android ApiDemos示例解析(43):App->Service->Remote Service Controller
- Android ApiDemos示例解析(42):App->Service->Remote Service Binding
- Android ApiDemos示例解析(38):App->Service->Foreground Service Controller
- Android ApiDemos示例解析(40):App->Service->Local Service Controller
- Android ApiDemos示例解析(27):App->Notification->Notifying Service Controller
- Android ApiDemos示例解析(44):App->Service->Service Start Arguments Controller
- Android ApiDemos示例解析(39):App->Service->Local Service Binding
- Android ApiDemos示例解析(41):App->Service->Messenger Service
- Android ApiDemos示例解析(20):App->Alarm->Alarm Service
- Android ApiDemos示例解析(19):App->Alarm->Alarm Controller
- Android ApiDemos示例解析(22):App->Dialog
- Android ApiDemos示例解析(23):App->Intents
- Android ApiDemos示例解析
- Android ApiDemos示例解析(3): App->Activity->Animation
- Android ApiDemos示例解析(4):App->Activity->Custom Dialog
- Android ApiDemos示例解析(5):App->Activity->Custom Title
- Android ApiDemos示例解析(6):App->Activity->Dialog
- Android ApiDemos示例解析(7):App->Activity->Forwarding
- php访问网络共享资源和本地文件
- 线程
- Android 内存分析方法整理
- 行为模式之状态模式(State Pattern)C++实现
- OpenGL ES on iOS
- Android ApiDemos示例解析(43):App->Service->Remote Service Controller
- 易语言学习中遇到的一些问题
- Twitter投资人:具有特定功能的小应用方能成功
- Android引路蜂地图开发示例:地图平移
- 备忘录模式
- 12年考研英语85分,我也来谈谈自己的复习过程(原创)
- win7 IE64位浏览器能上网,ie,搜狗等不能上网 的解决办法
- Silverlight 引路蜂二维图形库示例:动画Beziers曲线
- VC读取ini文件