来自不同项目的AIDL服务

时间:2013-09-11 12:03:59

标签: android eclipse aidl

我在eclipse的同一个工作区内有2个 *不同的项目* (大多数AIDL示例处理 相同的 项目中的不同进程)。项目A只是HelloWorld,它只显示2个数字的总和。我从一个名为MyFirstApp的客户端远程调用它来显示它。

问题:永远不会调用onServiceConnected()方法。

到目前为止我尝试了什么:

1)清单文件有android:process =“:remote”>标签。存在意图过滤器。是的,所有这些都在应用程序标签内。这是:

<service android:name=".ArithmeticService"
                     android:process=":remote">
                <intent-filter >
                    <action android:name="com.example.helloworld.ArithmeticService"/>
                </intent-filter>
            </service>
    </application>

2)在我的ArithmeticService中,函数onBind()不会简单地返回Null,而是返回mBinder。这是:

@Override
        public IBinder onBind(Intent intent) {
            // Return the interface
            Log.d(getClass().getSimpleName(),"IBinder");
            return mBinder;
        }

3)在客户端,接口的实现位于服务器端的同一个包中。

4)在我的客户端MainActivity的onCreate()函数中,我正在调用函数initConnection(),如下所示:

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);
        }
}

其余代码非常简单。单击按钮时,应调用远程服务器,并显示2个numbrs的总和。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

经过几天的尝试后得到它:项目的名称应该是 小案例 。它是Eclipse怪癖还是Android怪癖?我不知道。 但是工作正常。

相关问题