How to Create a android native service and use binder to communicate with it?

前端 未结 3 1894
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 15:50

My basic task is to create a native service in android and then write a simple native program to test it. lets say I want to write a simple service which return me sum of tw

3条回答
  •  囚心锁ツ
    2020-12-13 16:41

    The solution that I found is to use the Binders in native and use the

    defaultServiceManager()->addService(
            String16("TestService"),new CalcService());
    

    and then use binders and use following on client side.

    sp sm = defaultServiceManager();
    sp binder = sm->getService(String16("TestService"));
    

    I found examples here on how to do this: https://github.com/gburca/BinderDemo/blob/master/binder.cpp

提交回复
热议问题