简体   繁体   中英

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:

  1. Calculate the log/Antilog
  2. Display the answer on the screen
  3. 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.

It seems you execute the infinite loop on the Main-Thread (aka UI-Thread). Because of that the app wont respond to anything because it is busy disconnecting the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM