Add a static method to disable progressdialog:

Source: Internet
Author: User

 

Progressdialog mydialog = progressdialog. Show (yourclass. This, "connecting to server...", "connecting, please wait...", true, true );
Handler. Post (mtasks );
It is generally used when you use intent to start a new activity, you can add this sentence directly, it cannot achieve the effect you want.
You must use the following code to enable activity with intent in the run () method of a runnable object, and then run the thread using the handler. Post () method.
The Code is as follows:
Handler handler = new handler ();
Runnable mtasks = new runnable (){
Public void run (){
Intent intent = new intent ();
Intent. setclass (yourclass. This, edithome. Class );
Startactivity (intent );
}
};
Final progressdialog mydialog = progressdialog. Show (yourclass. This, "connecting to the server...", "connecting, please wait...", true, true );
Handler. Post (mtasks );

This is the result we want, but the progressdialog window is not closed, so mydialog. Dismiss () must be added later ();
In this case, the window disappears and we cannot see progressdialog... so we need to use a thread to control the time when the window disappears:

New thread (){
Public void run (){
Try {
Sleep (5000 );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
Mydialog. Dismiss ();
}. Start ();

The sleep time is the time you need to estimate the display time of the next activity. OK.
However, this is obviously unscientific. The scientific approach is: first, in the original avti.pdfAdd a static method to disable dialog:

Public static void closeprogressdialog (){
Mydialog. Dismiss ();
}

Then, add two member variables to the target activity:

Private Static final int event_time_to_change_image = 100;
Private handler mhandler = new handler (){
Public void handlemessage (Message MSG ){
Switch (msg. What ){
Case event_time_to_change_image:
Yourprimaryclass. closeprogressdialog ();
Break;
}
}};

Here, Handler registers the condition for closing the window and the closing action (call the static method ). Add the message sending code at the end of the oncreat () method of the activity:
Message message = mhandler. obtainmessage (event_time_to_change_image );
Mhandler. sendmessage (Message );
This ensures that the progressdialog is closed after all the target activities are displayed.
 

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.