无法绑定到远程服务

时间:2010-05-27 13:45:27

标签: android

致电后:

result=bindService(new Intent(IUdpListenerService.class.getName()),
            serviceConnection, Context.BIND_AUTO_CREATE);

byt debugger:result return'true'

未调用onServiceConnected。

*提到远程服务安装在diffrent apk中,并且由命令startService(..)启动

Okie ..这是我刚刚发现的新事物:onServiceConnected正在被触发,但它需要时间,所以这里发生的事情......当我使用我的界面实例时 - 它仍然是remine null,在onServiceConnected管理之前被触发..这可能吗? -

2 个答案:

答案 0 :(得分:3)

服务需要有一个<intent-filter>来执行操作:

    <service android:name=".BshService">
        <intent-filter>
            <action android:name="com.commonsware.android.advservice.IScript" />
        </intent-filter>
    </service>

然后,您可以使用Intent的操作表单绑定到它:

new Intent("com.commonsware.android.advservice.IScript")

或者,如果您的客户在IScript包中碰巧有一个名为com.commonsware.android.advservice的类或接口:

new Intent(IScript.getName());

答案 1 :(得分:1)

您使用的Intent构造函数需要Action,而不是类名。要启动某项服务,请改用new Intent(<package context, e.g. this>, IUdpListenerService.class)

更新:要在另一个包中启动服务或活动,请使用setComponent:

new Intent().setComponent(new ComponentName("com.remote", "com.remote.IUdpListenerService"));

(详见this问题)

相关问题