AIDL service from different Projects

邮差的信 提交于 2019-12-24 06:58:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!