gpt4 book ai didi

安卓服务测试

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:59:50 26 4
gpt4 key购买 nike

如何测试 ServiceonBind 上返回的 IBinder 对象?

最佳答案

这取决于您在上下文和服务之间使用的远程接口(interface)(在远程调用场景中)。例如你可以这样做:

IBinder service = this.bindService(new Intent(TestService.class.getName()));
assertNotNull(service);
assertTrue(service instanceof ITestServiceCall); //see if the service returns the correct interface
ITestServiceCall iTestServiceCall = ITestServiceCall.Stub.asInterface(service);
assertNotNull(iTestServiceCall);
iTestServiceCall.doSomething();

ITestServiceCall 是您在 AIDL 文件 (ITestServiceCall.aidl) 中定义的接口(interface)。

但在此之前,您必须确保您的服务在 onBind() 上正确返回接口(interface)的 stub 。

希望对您有所帮助。

关于安卓服务测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/793029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com