来自不同项目的AIDL服务 [英] AIDL service from different Projects

查看:98
本文介绍了来自不同项目的AIDL服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

Problem: The onServiceConnected() method is never invoked.

到目前为止,我已经尝试过:

1)清单文件具有android:process =:remote">标记.存在意图过滤器.是的,所有这些都在application标签内.在这里:

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)在我的ArithmeticService中,函数onBind()不仅返回Null,而且还返回mBinder.在这里:

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)在客户端,该接口的实现在服务器端的同一程序包中.

3) At client-side, the implementation of the interface is in the same package at the server side.

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

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

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

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.

任何帮助将不胜感激.

推荐答案

经过数天尝试后得到了它:项目名称应为 小写 .是Eclipse的怪癖还是Android的怪癖?我不知道.但可行.

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.

这篇关于来自不同项目的AIDL服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆