小编Ale*_*lex的帖子

Android 服务正确启动/绑定,但仅限第一次

我有一个服务在第一次调用时可以正确启动和绑定,但是当被其他活动调用时,对同一服务的连续绑定失败。

编码:

activity.startService(new Intent().setClass(activity, ServerListenerService.class));        

xmppServiceConnection = new ServiceConnection() {
        public void onServiceDisconnected(ComponentName name) {
            ServerActivityConnection.this.xmppService = null;
        }

        public void onServiceConnected(ComponentName name, IBinder binder) {
            //set everything up
        }
    };

activity.bindService(new Intent().setClass(activity, ServerListenerService.class), xmppServiceConnection, Activity.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)

第二次,在调用 之后activity.bindService,serviceconnection 的onServiceConnected方法永远不会被调用。我使用执行绑定的连接类,因此这两个活动的方法相同。该服务也正确添加了清单文件。

有任何想法吗?

非常感谢

android android-service

5
推荐指数
1
解决办法
894
查看次数

标签 统计

android ×1

android-service ×1