Android4.1中BinderService用法实例分析
本文实例讲述了Android4.1中BinderService用法。分享给大家供大家参考,具体如下:
Android4.1中出现了一个新的类,BinderService,所有的NativeService都会继承这个类。
classBinderService
{
public:
staticstatus_tpublish(boolallowIsolated=false){
sp<IServiceManager>sm(defaultServiceManager());
returnsm->addService(String16(SERVICE::getServiceName()),newSERVICE(),allowIsolated);
}
staticvoidpublishAndJoinThreadPool(boolallowIsolated=false){
sp<IServiceManager>sm(defaultServiceManager());
sm->addService(String16(SERVICE::getServiceName()),newSERVICE(),allowIsolated);
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
}
staticvoidinstantiate(){publish();}
staticstatus_tshutdown(){
returnNO_ERROR;
}
};
从代码中可以得知,这个类的publish(),就是将NativeService注册到ServiceManager,同时BinderService作为NativeService的友元类。这是因为BinderService需要访问NativeService的getServiceName方法。
希望本文所述对大家Android程序设计有所帮助。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语