Android Service
- 如果被bind的service在另外一个进程中
- ServiceConnection的onServiceConnected(ComponentName name, IBinder service)回调的IBinder service参数一定是一个android.os.BinderProxy对象
- 对于android.os.BinderProxy必须使用XxxService.Stub.asInterface(android.os.IBinder obj)才能得到XxxService的代理对象
- local service中返回的binder(没有使用aidl生成)因为没有.Stub.asInterface()调用,所以localService不能在另外的进程中启动
- service的android:process属性只有以":"(冒号)开头,新启动的进程才会以主进程名(一般为应用包名)为前缀
- 如果被bind的service在另外一个进程中
- ServiceConnection的onServiceConnected(ComponentName name, IBinder service)回调的IBinder service参数一定是一个android.os.BinderProxy对象
- 对于android.os.BinderProxy必须使用XxxService.Stub.asInterface(android.os.IBinder obj)才能得到XxxService的代理对象
- local service中返回的binder(没有使用aidl生成)因为没有.Stub.asInterface()调用,所以localService不能在另外的进程中启动
- service的android:process属性只有以":"(冒号)开头,新启动的进程才会以主进程名(一般为应用包名)为前缀
本文深入探讨了AndroidService在不同进程间的交互机制,特别关注ServiceConnection的onServiceConnected回调中IBinder参数类型的区别以及本地服务如何在相同进程中运行,通过实例解析了Android服务的生命周期管理和跨进程通信原理。

1万+

被折叠的 条评论
为什么被折叠?



