android - Show ProgressDialog while uithread sleeps? -


i want show progressdialog while uithread sleeps until data server retrived activity not shown. how can this?

you can use thread, asynctask, or service load data in background, , handler implementation control progressdialog.

the example in post shows how use thread login request, , in meantime show progress dialog.

using asynctask lot easier , clearer:

private static final int wait = 11; private final class mytask extends asynctask<void, void, void> {     @override     protected void onpreexecute()     {         super.onpreexecute();         // show dialog id=wait [11]         showdialog(wait);         // other actions must performed in ui thread         // before background works starts     }      @override     protected void doinbackground(void... params)     {         // perform background work         return null;     }      @override     protected void onpostexecute(void result)     {         super.onpostexecute(result);         // remove dialog id=wait [11]         removedialog(wait);         // other actions must performed in ui thread         // after background works finished     } }  [...]  final mytask task = new mytask(); task.execute(null); 

since asynctask generic type, can specify parameter types preference, handy transferring data ui thread background thread , back.

your dialog part few lines inside activity:

private progressdialog dialog;  @override protected dialog oncreatedialog(int id) {     switch (id)     {         case wait:         {             dialog = new progressdialog(this);             dialog.setmessage("loading...");             dialog.setindeterminate(true);             dialog.setcancelable(true);             return dialog;         }     }     return null; } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -