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。

更多相关文章

  1. No.11 使用firewall配置的防火墙策略的生效模式
  2. android studio 工程在android 源码编译
  3. 如何在JNI中抛异常
  4. Android(安卓)Retrofit和Rxandroid的使用
  5. Android(安卓)Activity启动模式全面解析
  6. android JNI 多线程 C函数回调
  7. Android(安卓)Boot Loader
  8. android bind service and remote service(aidl)
  9. Android(安卓)同一个Service已经启动再多调用startService

随机推荐

  1. Android(安卓)Camera预览
  2. Android开发指南(37) —— Data Backup
  3. 整理出15个Android很有用的代码片段
  4. setBackground和setBackgroundDrawable的
  5. [Android] 提高ORMLite插入大量数据效率
  6. Android的service相关讲解
  7. Android中使用log4j
  8. android 驱动文件权限设置
  9. Android(安卓)Orm框架(GreenDao)
  10. Android(安卓)LCD(二):LCD常用接口原理篇