我有一个作为绑定服务的应用程序。我正在向服务发送消息,但有时我收到以下错误:
E/AndroidRuntime(28216): java.lang.IllegalStateException: 指定的消息队列同步屏障令牌尚未发布或已被删除。
有时我会收到此错误:
android.util.AndroidRuntimeException: { what=888 when=0 } 此消息已在使用中。
有时用户界面只是冻结。我通过处理程序从服务到活动进行通信,反之亦然。
public void init(IBinder service){
playerService = new Messenger(service);
setBound(true);
try {
Message msg = Message.obtain(null, PlayerService.MSG_REGISTER_CLIENT);
msg.replyTo = messenger;
playerService.send(msg);
while(!messageQueue.isEmpty()){
playerService.send(messageQueue.remove());
}
} catch (RemoteException e) {
// In this case the service has crashed before we could even do anything with it
Log.d(Player.TAG, "problem binding player messenger " + e.getMessage());
}
}
这是一种在第二次调用时始终导致冻结的方法。
public void play(String url) {
Message msg = Message.obtain(null, PlayerService.PLAY, 0, 0);
msg.setData(getURLBundle(url));
sendMessage(msg);
}
private void sendMessage(Message message){
if(!isBound){
Log.d(Player.TAG, "isnt bound, queueing message");
messageQueue.add(message);
}else {
try {
playerService.send(message);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
我是线程、信使和处理程序的新手,因此感谢您提供任何帮助,谢谢:)