此消息无法回收,因为它仍在使用中(This message cannot be recycled because it is still in use)
我正在尝试使用本文来创建异步UDP套接字。
所以我有这个代码:
import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import java.net.DatagramSocket; import java.net.SocketException; public class UdpThread extends HandlerThread { private static final String TAG = "UDP"; private final Handler uiHandler, workerHandler; private final DatagramSocket socket = new DatagramSocket(); public UdpThread(final Handler uiHandler, final String hostname, final int port) throws SocketException { super(TAG); this.uiHandler = uiHandler; start(); workerHandler = new Handler(getLooper(), new Handler.Callback() { @Override public boolean handleMessage(final Message msg) { /* if (msg.what == port && msg.obj == hostname) { final InetSocketAddress address = new InetSocketAddress(hostname, port); Log.d(TAG, "Connecting to " + address); try { socket.connect(address); } catch (SocketException se) { throw new RuntimeException(se); } } */ msg.recycle(); //java.lang.IllegalStateException: This message cannot be recycled because it is still in use. return true; } }); workerHandler.obtainMessage(port, hostname).sendToTarget(); } }
但是当我运行代码时,我得到了提到的
java.lang.IllegalStateException: This message cannot be recycled because it is still in use.
当试图回收消息时。 为什么这样以及如何解决它并防止内存泄漏?I'm trying to use this article to create asynchronous UDP socket.
So I've this code:
import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import java.net.DatagramSocket; import java.net.SocketException; public class UdpThread extends HandlerThread { private static final String TAG = "UDP"; private final Handler uiHandler, workerHandler; private final DatagramSocket socket = new DatagramSocket(); public UdpThread(final Handler uiHandler, final String hostname, final int port) throws SocketException { super(TAG); this.uiHandler = uiHandler; start(); workerHandler = new Handler(getLooper(), new Handler.Callback() { @Override public boolean handleMessage(final Message msg) { /* if (msg.what == port && msg.obj == hostname) { final InetSocketAddress address = new InetSocketAddress(hostname, port); Log.d(TAG, "Connecting to " + address); try { socket.connect(address); } catch (SocketException se) { throw new RuntimeException(se); } } */ msg.recycle(); //java.lang.IllegalStateException: This message cannot be recycled because it is still in use. return true; } }); workerHandler.obtainMessage(port, hostname).sendToTarget(); } }
But when I run the code, I get the mentioned
java.lang.IllegalStateException: This message cannot be recycled because it is still in use.
when trying to recycle the message. Why is that and how to solve it and prevent memory leaks?
原文:https://stackoverflow.com/questions/44020010
最满意答案
您有两种方法可以实现此目的。 您可以使用Search Console,也可以使用Developer Console。
要使用Search Console方法,您需要拥有Google Play上应用的管理权限,并使用Search Console中的同一帐户登录。 在这里,您可以为应用添加新属性,并以支持的格式[android-app:// {apk_package_name} /]指定应用的根URI,类似于以下示例:
android-app://com.example/
接下来,SC会验证您的帐户是否与应用所有者的Play帐户相同,并自动验证应用属性。 但是,如果您的SC帐户与Google Play不同,您可以随时要求SC帐户的所有者将您添加为应用属性的所有者或用户。
然后验证过程最多可能需要48小时。 您可以在此处查看有关此流程的更多信息 - https://support.google.com/webmasters/answer/6178045
要使用Developer Console方法,您只需向网站站长发送请求即可。 一旦网站管理员批准您的请求,验证过程将立即开始,持续长达48小时。 您可以在此处获得有关此方法的更多信息 - https://support.google.com/googleplay/android-developer/answer/6041489
在您为深层链接使用HTTP方案的情况下,只需要这两种方法就可以将内容编入索引。 如果您使用自定义方案,则仍需要通过使用站点地图或网站注释来提供深层链接。
You have two options to accomplish this. You use the Search Console or you can use the Developer Console.
For using the Search Console approach, you need to have management rights on the app on Google Play and be logged in with that same account in Search Console. Here, you can add a new property for your app and specify the app's root URI in the supported format [android-app://{apk_package_name}/], similar as the following example:
android-app://com.example/
Next, the SC will verify if your account is the same as the app owner's Play account and automatically verify the app property. However, if your SC account is not the same as your Google Play, you can always ask the owner of the SC account to add you as an owner or user of the app property.
Then the process of validation can take up to 48 hours. You can see more information about this process in here - https://support.google.com/webmasters/answer/6178045
For using the Developer Console approach, you just need to send a request to the website webmaster. As soon as the webmaster approves your request, the process of validation will begin, lasting up to 48 hours as well. You can have more information about this approach in here - https://support.google.com/googleplay/android-developer/answer/6041489
These two approaches are all you need to do in order to get your content indexed, in the case that you use the HTTP scheme for your deep links. If instead you use a custom scheme, you still need to provide your deep links through the use of a sitemap or website annotations.
相关问答
更多-
您可以添加所有版本,但这不一定。 此外,您还可以为Google设置首选域名: https : //support.google.com/webmasters/answer/44231 You can add all versions, but that is not necessarily. Also, you can set up preferred domain for google: https://support.google.com/webmasters/answer/44231
-
如何在Search Console(网站管理员工具)上验证我的Android应用?(How to verify my Android app on Search Console (Webmaster Tools)?)[2023-07-22]
您有两种方法可以实现此目的。 您可以使用Search Console,也可以使用Developer Console。 要使用Search Console方法,您需要拥有Google Play上应用的管理权限,并使用Search Console中的同一帐户登录。 在这里,您可以为应用添加新属性,并以支持的格式[android-app:// {apk_package_name} /]指定应用的根URI,类似于以下示例: android-app://com.example/ 接下来,SC会验证您的帐户是否与应用 ... -
在gitlab ce中使用LetsEncrypt和Google网站管理员工具(Using LetsEncrypt and Google webmaster tools with gitlab ce)[2023-11-18]
通过GitLab Webroot Ubuntu上的GitLab CE的webroot默认为/opt/gitlab/embedded/service/gitlab-rails/public 。 您可以将googleXXXX.html复制到此目录中,并将LetsEncrypt的webroot指向此目录: ... [renewalparams] authenticator = webroot installer = None account = SOMEHASH [[webroot_map]] example.c ... -
Searchanalytics查询JAVA API v3(Google WebMaster工具)(Searchanalytics Query JAVA API v3 (Google WebMaster Tools))[2023-03-04]
我成功实现了Webmasters.Searchanalytics.Query如下 首先,您需要使用SearchAnalyticsQueryRequest类示例创建QueryRequest: private static SearchAnalyticsQueryRequest createSearchAnalyticsQueryRequest() { SearchAnalyticsQueryRequest searQueryRequest = new SearchAnalyticsQueryR ... -
这编译但它没有为我返回任何数据。 验证: public static WebmastersService WMAuthenticateOauth(string clientId, string clientSecret, string userName) { string[] scopes = new string[] { WebmastersService.Scope.Webmasters }; // View analytics data ...
-
我认为您应该扩展CErrorHandler以满足您的要求, 在404上发送电子邮件或将uri保存在数据库中或您需要做的任何事情 http://www.yiiframework.com/doc/guide/1.1/en/topics.error#displaying-errors I think you should extend CErrorHandler to meet your requirements, on 404 either send you an email or save the uri i ...
-
Google网站管理员工具在web2py中使用网站验证文件?(Google webmaster tools site verification file in web2py?)[2022-05-16]
我对更好的方法持开放态度,但是我将文件放在静态文件夹中并添加了routes_in条目: routes_in = ( ... ('/google1234a1ab1234a123.html', r'/my_app/static/google1234a1ab1234a123.html'), ... ) 现在它正在发挥作用。 I'm open to better methods but I put the file in the static folder and added a ... -
Google没有看到子域名...他们会看到子域名所在的文件夹。 删除该网站并再次添加为mydomain.com.au/m Google会看到它并将其添加到网站管理员工具中...我只是为我的子域做了这个。 这就是我如何解决它... Google doesn't see sub domains...they see the folder where the sub domain is located. Delete the site and add is again as mydomain.com.au/m G ...
-
是的,您必须使用HTTPS和Google数字资产链接 。 从链接的第二段开始 处理Android应用程序链接 链接的自动处理需要应用程序开发人员和网站所有者的合作。 开发人员必须配置其应用程序以声明与一个或多个网站的关联,并请求系统验证这些关联。 反过来,网站所有者必须 通过发布数字资产链接文件来 提供该 验证 。 数字资产链接文件是符合资产链接协议的语句集合,该协议对其他应用程序或网站进行公开,可验证的断言。 后来在同一页面上: 要点 :系统通过加密的HTTPS协议验证JSON文件。 无论您的应用的意图过 ...
-
如何在不对其编制索引的情况下在网站管理员工具中测试网站(How do I test a website in webmaster tools without indexing it)[2023-05-30]
没有机会对此进行测试,但我认为如果您向网站添加noindex标记,那么它仍然应该允许您的网站注册网站管理员工具,因为它仍然可以看到网站的内容以检测所有权。 我相信“以谷歌搜索”然后返回实时结果,而不是已经编入索引的内容(如果它不允许您检查新页面或重新检查更新的页面,那将不会非常有用),因此暂时删除noindex标记在运行时应该允许使用此功能(它也可以返回一些有用的信息而不删除它)。 事实“fetch as”有一个单独的“提交”按钮告诉我,它不会自动索引通过此方法找到的页面,所以这不应该是一个问题。 添加指向 ...