How to use AsyncTask to show a ProgressDialog while doing background work in Android? [duplicate]

Place your ProgressDialog in onPreExecute, sample code below: private ProgressDialog pdia; @Override protected void onPreExecute(){ super.onPreExecute(); pdia = new ProgressDialog(yourContext); pdia.setMessage(“Loading…”); pdia.show(); } @Override protected void onPostExecute(String result){ super.onPostExecute(result); pdia.dismiss(); } and in your onClickListener, just put this line inside: new EfetuaLogin().execute(null, null , null);

Show ProgressDialog Android

Declare your progress dialog: ProgressDialog progress; When you’re ready to start the progress dialog: progress = ProgressDialog.show(this, “dialog title”, “dialog message”, true); and to make it go away when you’re done: progress.dismiss(); Here’s a little thread example for you: // Note: declare ProgressDialog progress as a field in your class. progress = ProgressDialog.show(this, “dialog title”, … Read more

Android Fragments. Retaining an AsyncTask during screen rotation or configuration change

Fragments can actually make this a lot easier. Just use the method Fragment.setRetainInstance(boolean) to have your fragment instance retained across configuration changes. Note that this is the recommended replacement for Activity.onRetainnonConfigurationInstance() in the docs. If for some reason you really don’t want to use a retained fragment, there are other approaches you can take. Note … Read more

Custom Drawable for ProgressBar/ProgressDialog

I used the following for creating a custom progress bar. File res/drawable/progress_bar_states.xml declares the colors of the different states: <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@android:id/background”> <shape> <gradient android:startColor=”#000001″ android:centerColor=”#0b131e” android:centerY=”0.75″ android:endColor=”#0d1522″ android:angle=”270″ /> </shape> </item> <item android:id=”@android:id/secondaryProgress”> <clip> <shape> <gradient android:startColor=”#234″ android:centerColor=”#234″ android:centerY=”0.75″ android:endColor=”#a24″ android:angle=”270″ /> </shape> </clip> </item> <item android:id=”@android:id/progress”> <clip> <shape> <gradient android:startColor=”#144281″ android:centerColor=”#0b1f3c” android:centerY=”0.75″ … Read more

ProgressDialog in AsyncTask

/** * this class performs all the work, shows dialog before the work and dismiss it after */ public class ProgressTask extends AsyncTask<String, Void, Boolean> { public ProgressTask(ListActivity activity) { this.activity = activity; dialog = new ProgressDialog(activity); } /** progress dialog to show user that the backup is processing. */ private ProgressDialog dialog; /** application … Read more