java - How to display a message on android screen first and only then execute a method?
问题描述
I a developing an app which calculates log and Antilog of entered number and displays the same on the screen. However, as a part of the project this application also maliciously disconnect the connected Wifi network of the device. I have used wifiManager.disableNetwork(netId) and wifiManager.disconnect() to disconnect the connected network and used the infinite while loop to continue executing these.
However, I am not able to print the answer on the screen even when the display method is called first to display the answer and then the malicious method is called which repeatedly disconnects the connected Wifi network.
Is there any way by which, I can achieve the following:
- Calculate the log/Antilog
- Display the answer on the screen
- Call the method to execute the loop containing the code to disconnect the network
Note: I have 3 methods, 1 to calculate, 1 to display and 1 to run malicious code. However, the answer is displayed on the screen only after the method with malicious code completes executing the loop, if it is made as infinite loop the answer is never displayed and the application crashes. I want to display the answer first and only then execute the loop.
I am using JAVA on android studio. Any help is appreciated.
解决方案
看来您在主线程(又名 UI 线程)上执行了无限循环。因此,该应用程序不会响应任何内容,因为它正忙于断开 wifi 连接。
我建议,你看看线程并在一个新线程中执行循环。
在循环中,您应该在每次迭代时检查它是否仍然应该循环中断它不应该的循环。
推荐阅读
- amazon-web-services - AWS:创建新环境(tomcat-single-instance):带有 SSL 证书的 .ebextensions - 无法启动
- docusignapi - docusign NodeJS 中有没有一种方法可以使用 X-DocuSign-Authentication 进行身份验证
- laravel - Heroku 上部署的 API 的奇怪 ID 行为
- database - 将列表变量类型转换为 matplotlib 变量
- python - 值错误:错误长度 103 与索引 180 不匹配
- python - 如何将参数添加到在熊猫的 groupby 中调用的函数?
- javascript - 为什么我的可折叠链接在 Bootstrap 5 中不可点击?
- flutter - setState is not calling when Navigating to another page
- db2 - Installing a new DB2 subsystem at function level 100 (z/OS)
- .net-core - Using Audit.NET SqlDataProvider with Azure SQL and Managed Identity