Android Progress Dialog - android

I have a WidgetProvider which is around for milliseconds. It takes in an intent, and it kicks off a service which takes maybe noticeable time. I wanted to display something to the user during this delay like a progress bar that will block user, but the BroadcastReceiver/WidgetProvider seems like the wrong place to start up a progress bar. Where should I issue the Progress Bar in this case? Service maybe? but service might not be part of UI at all?

Where should I issue the Progress Bar in this case?
From a UI perspective, your only choice is to have it in the app widget itself. ProgressBar is one of the valid widgets to have in an app widget layout.
In terms of who updates the RemoteViews of your app widget to display/update/remove the ProgressBar, that is probably your Service in whatever background thread you are using for the "noticeable time".

Have you tried putting a progress bar in the notifications pull down? Doing something like the market displays when you're downloading an app should work really well, and execute in the background well.

Use can use AsynTask to display progress bar.

Related

Android ProgressBar animation

This seems like it should be a simple question, but for some reason I haven't come up with an obvious answer yet:
I have a horizontal progress bar displayed by my app while it does some work in the background. There are a finite amount of steps in this process, so I display actual progress rather than using an indeterminate progress bar.
However, there are occasionally steps in this process that take a very long time, so the progress bar is stationary for a while.
I could update the progress at a finer resolution, but I'd rather have the progress bar "pulse" or show some other constant animation just so that the user can see it is still working. I assumed Android would have this built in without me having to do much work, since it's such a common UI feature, but I can only seem to get this to work if I use an indeterminate progress bar.
Is there an easy way to do this, or do I have to write some kind of custom animation?

What is the difference between Progressbar and progressDialog?

I have searched everywhere and read the official doc of Google. But I still don't see the difference between them.
When should we use ProgressBar and when should we use ProgressDialog?
ProgressBar:
ProgressDialog:
The ProgressBar is a View, ProgressDialog is a Dialog.
While the answers here are informative, none really address the question.
Use a ProgressDialog when you want to prevent the user from
interacting with the application while waiting. The Dialog aspect
freezes the user from doing anything until it is dismissed. Note how the UI behind the ProgressDialog is grayed-out and inaccessible.
Use a ProgressBar to indicate that something in your app is still
waiting (loading, thinking, etc.) while the user may still interact with
other parts. In this image, the user can still fill out forms while waiting for the gps to respond.
(Thanks to Johnny S for the image of the ProgressDialog.)
ProgressBar is a View (like TextView, ImageView, Button, etc..), which can be used in your layout to show some progress.
ProgressDialog is a Dialog with 'built-in' ProgressBar. Dialogs can be used to make user wait while something is being computed. ProgressDialog makes it easier to show progress of your computation in dialog.
In addition to the differences pointed out in the rest of answers, you should take into account the following recommendation from Dialogs # Android Developer:
Avoid ProgressDialog
Android includes another dialog class called ProgressDialog that shows
a dialog with a progress bar. However, if you need to indicate loading
or indeterminate progress, you should instead follow the design
guidelines for Progress & Activity and use a ProgressBar in your
layout.
It may be also usefull to consider the following answers:
https://stackoverflow.com/a/12559601/2482894
How to avoid ProgressDialog in Android
When your iterations is countable (doing operations in loop, executing code x times etc.) use ProgressBar, if task is not countable status (like invoking web service) use ProgressDialog
From the android documentation
ProgressBar:Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has
progressed; the application can change the amount of progress
(modifying the length of the bar) as it moves forward. There is also a
secondary progress displayable on a progress bar which is useful for
displaying intermediate progress, such as the buffer level during a
streaming playback progress bar.
ProgressDialog:A dialog showing a progress indicator and an optional
text message or view. Only a text message or a view can be used at the
same time.

How to do a spinning animation while downloading a file

I have a program that copies a file to the sd card. The program takes a while to run, and now it just freezes while the file is being copied.
I saw some other programs that have a animation of a wheel spinning in the center of the screen while the file is being down loaed.
I tried to google spin control, but this brought up animation about a selector control using spinning wheels.
Is this feature built into the android?
Use a ProgressBar widget with indeterminate="true". You can use a ProgressDialog, read http://developer.android.com/guide/topics/ui/dialogs.html
Also, learn about threads, as you should be doing your file save in a background thread. http://developer.android.com/guide/components/processes-and-threads.html
You should use an AsyncTask to download the file. This will prevent your UI from freezing, and also easily allows you to show progress information if you want. If you want to let it download in the background, and let the user continue using the app, that's doable as well.
You can find an AsyncTask in one of my open source projects that downloads a file and shows the progress information using a progress bar here. You can change the style of the progress dialog to suit your needs.
I'm assuming you're using some sort of AsyncTask to download it?
If this is the case you can make an indeterminate progress bar start spinning right before you call task.execute() and then in onPostExecute() you can set the progress bar's visibility to view.GONE
here is an example on progress bars: http://codehenge.net/blog/2011/06/android-development-tutorial-progressbar-example/

Adding Progress bar in Global application in android

I would like to load progress bar when loading the application. I have 60 sound files which I have put in global application using sound pool. When I launch the application the application goes blank and it takes 30 to 40 seconds to load.
Instead of blank screen is it possible to put some progress bar with a background image until the application loads all the sound files?
I found out the global application doesn't support progress bar or background image? Is this true?
If not can somebody help me out in the above?
Thanks!
Load your sound files in an AsyncTask or a Thread.
You can set an OnLoadCompleteListener to know exactly when loading finishes.
If I'm right, and you mean your Application class, than you can't show a progressbar from there. But you have to have at least one activity, and you can show progressbars in your activity.
Also, you shouldn't make heavy operations on the UI thread such as this. Load the sounds in an AsyncTask, show the progressbar in the onPreExecute() method and hide it in the onPostExecute() method.

Splash screen while loading resources in android app

I'd like to have a splash screen while loading resources (images and sounds). How do I know everything is loaded?
Are all resources loaded at app startup?
Thanks
For accordingly implementing a splash screen in Android you want to:
Show a foreground screen with some progress indication for the user.
Execute a background thread for doing tasks that take some indefinitive time.
Both threads communicating between them, as you need the foreground to show the progress on the background.
Correctly kill the background thread when it finishes doing it's task. If you are planning to use AsyncTask in Android you have an issue there. (Link)
I've found this tutorial and I strongly suggest it:http://www.41post.com/4588/programming/android-coding-a-loading-screen-part-1
Part 1 accomplish this basic task, part 2 shows you how to correctly kill the AsyncTask. And part 3 puts a customized view in the foreground instead of the ProgressActivity.
You could do all your loading in an asyncTask then your onPostExecute remove the splash screen. This would help ensure that you don't block the UI thread while doing any expensive tasks that could cause an ANR popup.
Here you go, wrote a tutorial on how to create a SplashScreen with a progress bar:
http://blog.blundellapps.com/tut-splashscreen-with-progress-bar/
Basically, instead of your thread it starts an ASyncTask, you pass a reference to your progressSpinner into the ASyncTask and this will update it as the thread is downloading resources (or whatever you want to do).
Here is a complete tutorial on how to get it done. I've used this one myself with great results.
http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/

Categories

Resources