Android基础-- 利用handler发送消息报:"This message is already in use"解决办法

在利用handler发送消息时,遇到了一个问题如下:

 Caused by: android.util.AndroidRuntimeException: { when=-5ms what=33 obj=ResultData{token=android.os.BinderProxy@463a5238 results[ResultInfo{who=null, request=5, result=-1, data=null}]} target=com.tophealth.terminal.activity.StoreRegisterActivity$1 } This message is already in use.
                                                                          at android.os.MessageQueue.enqueueMessage(MessageQueue.java:312)
                                                                          at android.os.Handler.enqueueMessage(Handler.java:626)
                                                                          at android.os.Handler.sendMessageAtTime(Handler.java:595)
                                                                          at android.os.Handler.sendMessageDelayed(Handler.java:566)
                                                                          at android.os.Handler.sendMessage(Handler.java:503)

系统崩溃,老是报这个错,问题就很明显了。说明发送的消息正在消息队列中,表示现在正在被使用。解决办法重新创建一个新的消息,发送过去就ok啦!问题解决。

之前我的写法是:

 Message msg = new Message();
                case IMAGEVIEW_XKZ:
                    msg.what =11;
                    handler.sendMessage(msg);
                    break;

                case IMAGEVIEW_GSP:
                    msg.what =22;
                    handler.sendMessage(msg);
                    break;

                case IMAGEVIEW_YDZP:
                    msg.what =33;
                    handler.sendMessage(msg);
                    break;

                case IMAGEVIEW_YYZZ:
                    msg.what =44;
                    handler.sendMessage(msg);
                    break;

现在需要这样子修改就可以了:


                case IMAGEVIEW_XKZ:
                    Message msg1 = new Message();
                    msg1.what =11;
                    handler.sendMessage(msg1);
                    break;

                case IMAGEVIEW_GSP:
                    Message msg2 = new Message();
                    msg2.what =22;
                    handler.sendMessage(msg2);
                    break;

                case IMAGEVIEW_YDZP:
                    Message msg3 = new Message();
                    msg3.what =33;
                    handler.sendMessage(msg3);
                    break;

                case IMAGEVIEW_YYZZ:
                    Message msg4 = new Message();
                    msg4.what =44;
                    handler.sendMessage(msg4);
                    break;

你可能感兴趣的:(ios开发,android开发)