本文介紹了安卓服務(wù)測試的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
如何測試 Service
在 onBind
上返回的 IBinder
對象?
How to test my IBinder
object that Service
return on onBind
?
推薦答案
這取決于你在上下文和服務(wù)之間使用的遠(yuǎn)程接口(在遠(yuǎn)程調(diào)用場景中).例如,您可以這樣做:
It's according to the remote interface that you use between your context and the service (in remote call scenario). For example you can do like this:
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) 中定義的接口.
The ITestServiceCall is the interface that you define in an AIDL file (ITestServiceCall.aidl).
但在此之前,您必須確保您的服務(wù)在 onBind() 上正確返回接口的存根.
But before this can work you have to make sure your service returns the Stub of your interface correctly on onBind().
我希望這會有所幫助.
這篇關(guān)于安卓服務(wù)測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!