How to force the onServiceDisconnected() get called?

前端 未结 2 712
故里飘歌
故里飘歌 2020-12-17 04:37

After I have bound a service by calling:

bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);

I need fo

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 05:17

    You might just unbind your service

    public void openService {
    mConnection = new ServiceConnection() {
                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    mService = IService.Stub.asInterface(service);
                }
                @Override
                public void onServiceDisconnected(ComponentName cn) {
                    mService = null;
                }
            };
             bindService(service, mConnection, Context.BIND_AUTO_CREATE);   
        }
    }
    
    public void closeService() {
        unbindService(mConnection);
        stopService(new Intent(this, Service.class));
    }
    

提交回复
热议问题