Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the progress bar of child threads is not displayed by Android

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "Android how to solve the problem that the child thread progress bar does not display", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "Android how to solve the problem that the child thread progress bar does not show".

The code logic of the progress bar is not displayed:

First, you create a new class that has an inner class that inherits Therad

There is a normal method in the class, and the inner class in this method is called when the ordinary method is executed.

At this point, the progress bar is displayed.

The progress bar is shown in the ordinary method, so the actual display time is only shown after the inner class execution is completed, which is of course not possible.

If the progress bar is displayed in the child thread, it will report an error, but Baidu's method will not work. What should I do?

Solution:

Create a common method in the class

The child thread is directly new in the method and then start

The child thread returns the data result of the time-consuming operation to handler through the handler message mechanism.

Handler receives the message and processes it accordingly.

Handler can jump directly to activity. This is more important.

Part of the code shows:

Handler Code:

Handler handler = new Handler () {

@ Override

Public void handleMessage (Message msg) {

Super.handleMessage (msg)

If (msg.what==0) {

Pb.dismiss ()

String data = (String) msg.obj

If (data.equals ("0")) {

Toast.makeText (context, "Verification failed, please log in again", Toast.LENGTH_LONG) .show ()

SqliteDao sqliteDao = new SqliteDao (context)

SqliteDao.deletebbusinessdocumentlogin ()

} else {

Toast.makeText (context, "Verification successful", Toast.LENGTH_LONG) .show ()

Intent intent = new Intent (context, ordergoods.class)

Context.startActivity (intent)

}

}

}

}

The child thread returns the code that the result set is sent to handler:

Handler.obtainMessage (0grammndata). SendToTarget ()

The above is all the content of the article "how to solve the problem that the child thread progress bar does not show up with Android". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report