`
zhonglunshun
  • 浏览: 138983 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

This message is already in use.的解决办法

阅读更多

This message is already in use.的解决方法

 

在开发项目的时候遇到报错This message is already in use.然后我看了下是和handler发送Message相关的,于是我就在网上找解决办法。其实意思就是说,这个消息已经在消息队列了,而且正被使用,而如果往同一个队列发送相同的西哦奥西对象就会报错。

这样,解决就很简单了,我们只需要判断这个消息是否在队列中有了,有了我们new一个一模一样的消息对象,然后发出去,这样就不会报错了。

 

下面贴出我之前的代码和修改后的代码:

 

报错的:

public void onMessage(Message msg) {
		handler.sendMessage(msg);
	}

 修改后的:


public void onMessage(Message msg) {
		if(handler.obtainMessage(msg.what, msg.obj) != null){
			Message _msg = new Message();
			_msg.what = msg.what;
			_msg.obj= msg.obj;
			msg = _msg;
//			return;
		}
		handler.sendMessage(msg);
	}

 

这样问题就解决了,当然效果怎么样我这里没测试,希望对大家有帮助。

0
1
分享到:
评论

相关推荐

    计算机网络第六版答案

    (This is a little bit of a white lie, as modern routers sometimes act as firewalls or caching components, and process Transport layer as well.) Link layer switches process link and physical layers ...

    数据结构作业Hash表

    Note: the stl vector is used in this assignment, if you have any difficulties, you can refer to the documents given in this folder. Submission Submit only the following. 1. hashset.cpp – your ...

    Java邮件开发Fundamentals of the JavaMail API

    stands for Internet Message Access Protocol, and is currently in version 4, also known as IMAP4. When using IMAP, your mail server must support the protocol. You can't just change your program to ...

    servlet2.4doc

    Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. encodeUrl(String) - Method in class javax.servlet....

    EurekaLog_7.5.0.0_Enterprise

    1)....Fixed: Confusing message in Manage tool when using with Trial/Pro 2)....Fixed: Range check error in processes information for x64 machines (affects startup of any EurekaLog-enabled module) 3)......

    hash table spell checking

    Note: the stl vector is used in this assignment, if you have any difficulties, you can refer to the documents given in this folder. Submission Submit only the following. 1. hashset.cpp – your ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache ...

    CAN Specification Version 2.0

    make use of the CAN implementations that are already available on the market, or of new controllers that implement both formats. In order to distinguish standard and extended format the first reserved...

    php.ini-development

    in production environments and one that is recommended to be used in ; development environments. ; php.ini-production contains settings which hold security, performance and ; best practices at its ...

    数位板压力测试

    This specification was developed in response to a perceived need for a standardized programming inter-face to digitizing tablets, three dimensional position sensors, and other pointing devices by a ...

    apktool documentation

    This file is copied to $HOME/apktool/framework/1.apk during use. Warning Apktool has no knowledge of what version of framework resides there. It will assume its up to date, so delete the file ...

    gettext-0.18.2.tar.gz

    This is true not only from within GNU, but also in a great deal of proprietary and free software. Using a common language is quite handy for communication between developers, maintainers and users ...

    linux 0.11 kernel开发包 适于进行Linux OS研究

    # This is a root file system for linux 0.11 kernel. # Rebuild from materials gathered from Internet. # # Zhao Jiong ( gohigh@sh163.net ) # http://oldlinux.org/ 2004.1.4 # Third ...

    微软内部资料-SQL性能优化3

    If a match is found, it knows that resource is already locked. Some of the resources have “sub-resources.” The followings are sub-resources displayed by the sp_lock output: Database Lock Sub-...

    a project model for the FreeBSD Project.7z

    [1] This paper will provide such a project model and is donated to the FreeBSD Documentation project where it can evolve together with the project so that it can at any point in time reflect the way ...

    STG (SNMP Traffic Grapher)

    Note, it is in bytes in second, so if you want to monitor 1Mbit line it should be set a little higher than 131072 Reverse option - changes direction of graph. Show traffic in Bytes / Bits - ...

    ODTforVS2017.7z

    Please note: In rare cases this installation may fail with a message to check a log file for more details and it may remain partially installed. This may cause an "already installed" error when you ...

    flash标签云 3D效果 PHP插件 by weefselkweekje

    * In 99% of all cases where this happens the issue is caused by markup errors in the page where the plugin is used. Please validate your blog using [validator.w3.org](http://validator.w3.org) and fix ...

    VC技术内幕第五版.chm

    Like many of my colleagues in this industry, I learned Windows programming from Charles Petzold's Programming Windows—a classic programming text that is the bible to an entire generation of Windows ...

    erlang日志应用log4erl(非sasl)

    2- Once the log4erl directory is included, you can use its API as described in section "API". but before, you need to run: > application:start(log4erl). 3- Create a configuration file and load it ...

Global site tag (gtag.js) - Google Analytics