简体   繁体   English

如何先在android屏幕上显示一条消息,然后才执行一个方法?

[英]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:有什么方法可以实现以下目标:

  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.注意:我有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.

相关问题 如何在 Android 中完全执行第一种方法后执行第二种方法? - How to Execute second method after first method fully executed in Android? 如何只显示几秒钟的屏幕 Android Studio - How to display a screen only for some seconds Android Studio 在Android上使用Paho的MQTT,仅接收第一条消息 - MQTT with paho on android, only receiving first message 如何获得启动画面以显示消息? - how to obtain a splash screen to display a message? 在多个Android设备中同时执行方法(屏幕闪烁) - Execute method(screen flasher) at same time in multiple android device's 如何将显示方法添加到Java链表实现中,该实现仅显示列表中的前10个项和后10个项? - How to add a display method to a Java Linked List implementation that displays only the first and the last 10 items on the list? 如何只显示一次提交屏幕? - How to display Submit Screen only one time? 如何在 android app 中实现一种可以收集屏幕上显示什么信息的方法 - How to implement a method which can collect what information is display on the screen in android app fragment_display_message:我的第一个Android应用程序错误 - fragment_display_message : My first Android app error 当活动屏幕首次在 Android Studio 上加载时,如何在隐藏背景中发送带有当前位置数据的 SMS 文本消息? - How do I send a SMS text message in the hidden background with current location data when the activity screen first loads on Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM