我有一个远程服务、一个远程服务接口和一个绑定到它的客户端。我想知道是否可以在服务中调用未在服务上下文的接口中公开的方法(例如 UnexposedMethod2)。
我的代码如下:
SomeService.java:
public class SomeService extends IntentService {
private IRemote.Stub iremote_sub = new IRemote.Stub(){
public String SomeMethod(String key) throws RemoteException {
return SomeService.this.UnexposedMethod1(key);
}
};
private String UnexposedMethod1(String key){
/* Do Something With key */
........................
return UnexposedMethod2();
}
public String UnexposedMethod2(){
String str = new String();
/* Do Something With str and Fetch Data from Providers */
return str;
}
}
IRemote.aidl:
interface IRemote{
String SomeMethod(String key)
}
SomeActivity.java:
public class SomeActivity extends Activity {
private ServiceConnection myConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
myService = IGetContactsString.Stub.asInterface(service);
/* Can I call UnexposedMethod2 here on service's context? */
}
public void onServiceDisconnected(ComponentName className) {
myService = null;
}
};
}
任何建议都是有帮助的。非常感谢!