Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid ProgressDialog in Android

Tags:

android

Dialogs @ Android Developer says to avoid ProgressDialog to indicate loading, and instead, to put an activity indicator right in the layout.

Progress & Activity @ Android Developer discusses activity indicators, but doesn't name the classes used. I've had no luck searching for Android classes with names like ActivityBar, ActivityCircle, or ActivityIndicator.

Where can I find documentation (tutorials, examples, or API documentation) on Android's support for including activity indicators right in my layout, avoiding a ProgressDialog?

Update: full.stack.ex pointed me the right answer.

First, include the following code in the Activity's onCreate() method before invoking setContentView():

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

Next, just before loading (e.g. firing up an AsyncTaskLoader), use this call to make the spinner appear:

setProgressBarIndeterminateVisibility(true);

Finally, after the load is completed, hide the spinner again:

MainActivity.this.setProgressBarIndeterminateVisibility(false);

Bingo! No ProgressDialog required. Making the spinner visible seems to slow down loading considerably in the emulator (it takes minutes instead of seconds), but not on my actual phone. I'm not sure if there's any way to make the spinner use fewer CPU cycles.

like image 995
Canuck Avatar asked Jan 23 '13 14:01

Canuck


People also ask

How do I turn off progress dialog?

getText(R. string. msg_dlg_analyse_pic), true, //indeterminate true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { m_bRunning = false; } });

What is ProgressDialog in android?

ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.

Why is ProgressDialog deprecated?

ProgressDialog 's look can be replicated by placing a ProgressBar into an AlertDialog . You can still use it, but Android does not want you to use it, that is why it is deprecated.


3 Answers

It's not really obvious from the documentation that there's a window feature for that.

It's a built-in progress indicator:

Activity.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

developer.android.com/reference/android/app/Activity.html#requestWindowFeature(int)

like image 76
full.stack.ex Avatar answered Oct 10 '22 02:10

full.stack.ex


You're talking about ProgressBar class (I guess): http://developer.android.com/reference/android/widget/ProgressBar.html

like image 27
XorOrNor Avatar answered Oct 10 '22 03:10

XorOrNor


Ive tended to use an animated gif image in the past. Good site for generating them is

http://www.ajaxload.info/

like image 28
ElPedro Avatar answered Oct 10 '22 04:10

ElPedro