问题
I have 2 * different projects* within the same workspace in eclipse (most AIDL examples handle different processes within the same project). Project A is simply HelloWorld, that just displays the sum of 2 numbers. I'm calling this remotely from a client called MyFirstApp to display it.
Problem: The onServiceConnected() method is never invoked.
What I've tried so far:
1) Manifest file has android:process=":remote"> tag. Intent filter is present. AND YES, ALL OF IT IS WITHIN THE application tag. Here it is:
<service android:name=".ArithmeticService"
android:process=":remote">
<intent-filter >
<action android:name="com.example.helloworld.ArithmeticService"/>
</intent-filter>
</service>
</application>
2) In my ArithmeticService, the function onBind() does not simply return Null, but returns mBinder. Here it is:
@Override
public IBinder onBind(Intent intent) {
// Return the interface
Log.d(getClass().getSimpleName(),"IBinder");
return mBinder;
}
3) At client-side, the implementation of the interface is in the same package at the server side.
4) In the onCreate() function of my client's MainActivity, I'm calling the function initConnection(), which is as follows:
void initConnection(){
mServiceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
mService = null;
Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_SHORT).show();
Log.d("IRemote", "Binding - Service disconnected");
}
@Override
public void onServiceConnected(ComponentName name, IBinder service)
{
// TODO Auto-generated method stub
mService = IRemote.Stub.asInterface((IBinder) service);
Toast.makeText(getApplicationContext(), "yes", Toast.LENGTH_SHORT).show();
Log.d("IRemote", "Binding is done - Service connected");
}
};
if(mService == null)
{
Intent it = new Intent();
it.setAction("com.example.helloworld.ArithmeticService");
//binding to remote service
bindService(it, mServiceConnection, Service.BIND_AUTO_CREATE);
}
}
Rest of the code is pretty simple. On click of a button, the remote server should be invoked and the sum of 2 numbrs should be displayed.
Any Help shall be very appreciated.
回答1:
Got it after days of trying: The name of the project should be in small-case. Is it an Eclipse quirk, or Android quirk ? I don't know. BUT IT WORKS.
来源:https://stackoverflow.com/questions/18740677/aidl-service-from-different-projects