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