Android Display Progress Dialog while doing a background task - android

I am building an android app which will download some data and display it to the user. Now I need to show a circular progress bar until the data is downloaded. The download will begin on a button click. How can I achieve this? Sample code would be very helpful.

You need to use an AsyncTask to execute your download and ProgressBar instance to show a circular progress.
There are many resources you can find which describe exactly how to use the combination to do what you want.

Check Android AsyncTask class for what you want to achieve.
Basically you start showing a ProgressDialog in the onPreExecute of AsyncTask and dismiss it in onPostExecute when your background job is done.
Check these also.
android how to work with asynctasks progressdialog
http://twigstechtips.blogspot.com/2011/11/for-my-app-moustachify-everything-i-was.html
http://javatech.org/2011/02/discovering-android-opening-a-progress-dialog-with-asynctask/

Related

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.

Android progress dialog without using Threads

Is it possible to get a progress dialog (a "loading..." one, not a percentual one) without using threads? I would even accept a custom dialog with an static image instead of the loading animation. So, is it possible? How?
Its not possible.
I would recomend using an AsyncTask which is what the Android Team made to simplify threading.

Creation "Loading Screen" for Android

I parse the .html page and take set of checkbox, than I add checkboxes to layout and setContentView(layout). But parsing is slow, and I want to create loading window during data is loading. I don't know how to do it, help me please. Thank you for, anyway.
For that you can implement AsyncTask (Painless Threading), implement ProgressBar inside the onPreExecute() method of AsyncTask.
As i have marked it is known as Painless Threading as we developer need not to bother about to start/pause/stop the thread, it is managed by Android itself.
Update:
You can also show ProgressDialog inside the onPreExecute() method and then hide the same in onPostExecute() method. For the same, i suggest you to go through this article, really helpful: https://sites.google.com/site/androidhowto/how-to-1/asynctasks-with-progressdialogs
You can do this using a progress dialog. There is a tutorial on the Android Developers Website, and this is where It starts to explain:
A ProgressDialog is an extension of the AlertDialog class that can
display a progress animation in the form of a spinning wheel, for a
task with progress that's undefined, or a progress bar, for a task
that has a defined progression. The dialog can also provide buttons,
such as one to cancel a download.
The Link is here: http://developer.android.com/guide/topics/ui/dialogs.html

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