UAS*_*UAS 17 service android unbind
我英语不好,但我会尽力解释我的问题.
所以,问题是:
1)我有一个本地服务
2)我启动它然后绑定它.3)当我即将关闭该服务时出现问题.永远不会调用我的类ServiceConnection实现中的onServiceDisconnected方法.如果我手动(从设置),或通过unbindService,或通过stopService,或通过unbindService和stopService的组合关闭它 - onServiceDisconnected仍然不会被调用.我究竟做错了什么?
简短的代码如下:
protected ServiceConnection mServerConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
Log.d(LOG_TAG, "onServiceConnected");
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d(LOG_TAG, "onServiceDisconnected");
}
}
public void start() {
// mContext is defined upper in code, I think it is not necessary to explain what is it
mContext.bindService(i, mServerConn, Context.BIND_AUTO_CREATE);
mContext.startService(i);
}
public void stop() {
mContext.stopService(new Intent(mContext, ServiceRemote.class));
mContext.unbindService(mServerConn);
}
Run Code Online (Sandbox Code Playgroud)
我正在Android 2.2的模拟器下测试此代码
dar*_*rma 29
onServiceDisconnected仅在极端情况下被调用(崩溃/被杀死).
由于所有应用程序组件通常在同一进程中运行,因此本地服务不太可能发生这种情况......这意味着,除非您有意解除绑定或销毁服务,否则它应该保持连接状态,或者与使用它的组件一起消亡.
| 归档时间: |
|
| 查看次数: |
16909 次 |
| 最近记录: |