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. |