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.
getText(R. string. msg_dlg_analyse_pic), true, //indeterminate true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { m_bRunning = false; } });
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.
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.
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)
You're talking about ProgressBar class (I guess): http://developer.android.com/reference/android/widget/ProgressBar.html
Ive tended to use an animated gif image in the past. Good site for generating them is
http://www.ajaxload.info/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With