我英语不好,但我会尽力解释我的问题.
所以,问题是:
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的模拟器下测试此代码
我想在我的应用程序中收到短信,但我不希望我的Android显示有关该事件的通知.算法:
收到短信(没关系)
如果这是具有特殊内容格式的短信(对于我的应用) - 使用我的应用处理它并且不显示通知.
如果这是一条简单的消息 - 我不想处理它,所以必须显示通知.
我试图使用有序广播,但它没有帮助.在某处我读到SMS_RECEIVE的广播没有订购,但我看到了一些应用程序,可以在没有通知的情况下接收短信.
有没有人可以帮助我或告诉我解决这个问题的正确方法?
abortBroadcast()
在广播中呼叫没有帮助