Android sub-thread progress bar does not display issues

Source: Internet
Author: User

The code logic for the progress bar is not displayed:

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

There is a common method in the class that calls the inner class in this method when the normal method executes.

At this point, the progress bar is displayed.

The progress bar is shown in the normal method, so the actual time shown is displayed after the internal class execution is completed, which of course is not possible.

Progress bar in sub-thread display is error, Baidu method tried not. How to do it.

Solution:

Create a common method in the class,

In the method, the child thread is directly new and start

The data results of the time-consuming operation are returned to handler by the handler message mechanism in the child thread

The handler receives the message and makes the corresponding processing.

Handler is a direct jump to activity. This is more important.

Some 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 re-login" ,toast. ). Show ();

Sqlitedao Sqlitedao = New Sqlitedao (context);

Sqlitedao.deletebbusinessdocumentlogin ();

}else {

                 Toast. maketext context "Validation succeeded" Toast. ). Show ();

Intent Intent = New Intent (context, ordergoods. class );

Context. StartActivity (intent);

}

}

}

};

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

handler. Obtainmessage (0,returndata). Sendtotarget ();

Android sub-thread progress bar does not display issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.