Service的疑惑?望赐教!

中才德创 2014-06-16 02:39:40
eeeService的IBinder return mBinder
gggService 的IBinder return null
说明前者是远程service,后者是本地service。
前者多了个android:process说明项,为什么呢?
两者都是android:exported="false",都是只限于本项目使用。那远程service的设计岂非多余了?

<service
android:name="aaa.bbb.ccc.ddd.eeeService"
android:label="fff"
android:process=":eeeService"
android:exported="false">
</service>

<service
android:name=".ddd.gggService"
android:label="gggService"
android:exported="false" >
</service>
...全文
251 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
androidfordahai 2014-06-19
  • 打赏
  • 举报
回复
楼上正解
Darcy杨 2014-06-19
  • 打赏
  • 举报
回复
是的,
中才德创 2014-06-18
  • 打赏
  • 举报
回复
可以这么理解吗? 若有android:process=":eeeService"这一句,则此Service是有自己独立进程的。反之,与主Activity是在一个进程里的。
Darcy杨 2014-06-17
  • 打赏
  • 举报
回复
是由process指定的,是不是远程接口对开发者来说是透明的,比如

					@Override
					public void onServiceConnected(ComponentName name, IBinder service) {
						myInterface = QServiceInterface.Stub.asInterface(service);
					}
QServiceInterface.Stub.asInterface这个自动生成的方法自己会判断IBinder service是本地接口还是远程接口,然后asInterface总是会返回给你一个正确的结果
中才德创 2014-06-16
  • 打赏
  • 举报
回复
在同一个工程项目里: service和其他的activity/service可以在不同的process里面,是不是由android:process=":eeeService"界定的。 否则,下面的代码,谁知道它是Remote接口还是Binder本身
@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return mBinder;
}
private final IXXXService.Stub mBinder = new IXXXService.Stub() {
...
}
Darcy杨 2014-06-16
  • 打赏
  • 举报
回复
process和exported两者之间没有什么必然联系。 同一个Application里面,service和其他的activity/service可以在不同的process里面,这时候bindService时返回的就是Remote接口;如果service和activity在同一个process里面,返回的就是Binder本身,直接调用就可以。 exported是用来指定非同一个application(package不一样)是否可以调用,跟在哪个进程里面关系不大,不过通常来说不同的application运行在不同的process里面。

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧