[英]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.我正在开发一个应用程序,它计算输入数字的 log 和 Antilog 并在屏幕上显示相同的内容。 However, as a part of the project this application also maliciously disconnect the connected Wifi network of the device.
但是,作为该项目的一部分,该应用程序还会恶意断开设备连接的 Wifi 网络。 I have used wifiManager.disableNetwork(netId) and wifiManager.disconnect() to disconnect the connected network and used the infinite while loop to continue executing these.
我已经使用 wifiManager.disableNetwork(netId) 和 wifiManager.disconnect() 断开连接的网络并使用无限 while 循环继续执行这些。
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.但是,即使首先调用 display 方法显示答案,然后调用恶意方法反复断开连接的 Wifi 网络,我也无法在屏幕上打印答案。
Is there any way by which, I can achieve the following:有什么方法可以实现以下目标:
Note: I have 3 methods, 1 to calculate, 1 to display and 1 to run malicious code.注意:我有3种方法,1种计算,1种显示,1种运行恶意代码。 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.我在 android studio 上使用 JAVA。 Any help is appreciated.
任何帮助表示赞赏。
It seems you execute the infinite loop on the Main-Thread (aka UI-Thread).看来您在主线程(又名 UI 线程)上执行了无限循环。 Because of that the app wont respond to anything because it is busy disconnecting the wifi.
因此,该应用程序不会响应任何内容,因为它正忙于断开 wifi 连接。
I'd suggest, you take a look at Threading and execute the loop in a new Thread.我建议,你看看线程并在一个新线程中执行循环。
Within the loop you should check at each iterationt that it should still loop an break the loop it is shouldn't.在循环中,您应该在每次迭代时检查它是否仍然应该循环并打破它不应该的循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.