android progressDialog is static - android

I have an issue with my ProgressDialog object. When I show it first time, it is spinning, but after I dismiss it and show it again, the dialog is static, it it not spinning... Can you please tell me why? All of this happens in the UI thread. Thanks

are you doing any processing in the UI thread during the second show of the ProgressDialog? If so, you need to move the processing to a background thread. Otherwise, the progress dialog does not get the CPU to update(spin) itself.

Related

About AsyncTask updating UI thread with dialog

I'm developing an Android app that has a basic structure: activity that requests some action from AsyncTask implementer. The implementer has 3 custom methods that should be able to update UI thread with a Dialog and a postExecute() that should update UI thread with a failuer Dialog if an exception is thrown. Here are some questions:
Where should I create the Dialog object? In the activity class or the AsyncTask implementer? What general guidelines should I follow?
Can I update UI thread with a Dialog without waiting for postExecute()?
How can I update UI thread with a picture? Should I create a custom Dialog or is there an easier way?
If the updates - as dialogs with pictures - come one after another, in a sequence how should I deal with it? Should I create some kind of queue? How would you do it?
Thank you in advance :)
1)There's a couple of different ways you can do this. But personally I usually create the dialog in onPreExecute of the AsyncTask, so that the UI for the task is completely self contained.
2)Yes. You can do it in onProgressUpdate. doInBackground should call publishProgress() which will cause onProgressUpdate to be called on the UI thread.
3)Too few details- where do you want the picture? In an existing image view? On top of the current layout? If you just want to display it in a dialog box, an AlertDialog with custom layout would probably work.
4)Depends on the app. Do you want the user to see all the images, or is it ok to miss images in the middle if a new one is sent?

Progress Dialog is not spinning enough in asynctask in android

I am using progress dialog in my Asynctask class. I put progressdialog.show() on onpreExecte() method of asynctask and dismissing the dialog in onPostExecute. My problem is the wheel in dialog is stops after 2-3 seconds but my background process is working. Can anyone help me to solve this problem? I want to spin the wheel until the background process is over.
Check tutorials how to do asynchronus task in Android:
link
link
link
link
link.
And here are some other StackOverflow questions that are similar:
Progress dialog problem in Android
Progress Dialog on open activity
Progress Dialog while starting new activity
Android: Progress Dialog spinner not spinning
Updating progress dialog
android: showing a progress dialog
Just a guess, but it seems to me that starting the progress dialog INSIDE the AsyncTask causes the dialog to work on the AsyncTask thread, instead of the UI thread.
I suggest moving the progressdialog.show() to just before you call execute() in your Activity.

Whats the best way to display a progress bar at the start of calculations then hide it at the end

..without putting the calculation code into an asyncTask but the progress logic can be in an asynctask
Im looking for something like this
onCreate(){
ShowProgressBar()
...
do many operations
....
hidePogressBar()
I've tried putting the progress bar in an async task but it's complaining that it belongs to a different thread. and even if it worked, there is no way of stopping it once it starts in doInBackground() unless I hide it at the onPostExecute() which means it will disappear as soon as it starts because there is nothing in doInBackground()
How can I do this?
I've tried putting the progress bar in an async task but it's complaining that it belongs to a different thread.
Post the logcat from that and we can help figure out what is going wrong
there is no way of stopping it once it starts in doInBackground() unless I hide it at the onPostExecute() which means it will disappear as soon as it starts because there is nothing in doInBackground()
If there is no work to be done then there would be no point of having a ProgressDialog.
Put whatever work you are doing in the doInBackground() then it will call onPostExecute() and you can dismiss() your ProgressBar from there
Show your progress bar in onPreExecute()

Android: Blocking RPC with progress dialog

I have an Android App that uses an RPC mechanism to set/get information to/from a server. I call the RPCs from whithin the main thread (blocking) and I want them to be blocking. However, sometimes a call can last for some seconds and I'd like to display an indeterminate progress dialog after some specified time (e.g. 1 second).
I tried to spawn a new thread that makes the call and the main thread waits in a loop (with sleeps) until the call has been finished. Inside this loope I show the progress dialog but this is not working.
Is it possible to show and update the progress dialog inside another Thread or does anybody know a better solution that allows me to use blocking calls?
You cannot do both, make the main thread wait in a loop and show a progress dialog, at the same time. Either the main thread waits or shows the dialog.
Why do you want to block the main thread? Communication over the internet should always be done in a background thread because you never know how long it will take to complete. Do that stuff in AsyncTask and show the progress dialog in main.
Try using AsyncTask. It is an android mechanism which is used to make such network calls. Get the brief detailing of AsyncTask here:
Using AsynTask to show progress bar while attempting to SSH to Server
Using a AsyncTask you can block the user from proceeding ahead. You have to show a progress dialog in the onPreExecute() method of the AsyncTask. All your network related activities will take place in doInBackground(). After the background action is completed there will be a call to onPostExecute() where the progress dialog will be dismissed.
AsyncTask is a asynchronous call because you have 2 threads working simultaneously, one is the UI thread on which you are showing your progress dialog and the other is the non-ui background thread which is fetching your data from the server.
Hope this explanation helps.
I have found a solution that seems to work (at least I havent noticed any problems yet). I know the proper way would be to use somethn like AsyncTask but in my case I have no benefit from it and it complicates the program logic.
To update the UI within a new thread:
new Thread()
{
public void run()
{
Looper.prepare();
... do UI stuff here
Looper.loop();
}
}.start();

Changing Progress Dialog Message While Running

I've got a fairly simple issue I'm not sure how to resolve. I want to change the message text of a Progress Dialog while it's running and showing. An example of this would be something like a "time remaining" counter that would count down while the progress animation is spinning. I'm not sure how I would approach this because doing progressDialog.setMessage(String), even within a running thread, will not change anything in the Dialog itself. Thank you!
You might want to check this question out.
In short: You need to create a little Runnable which you can execute on the UI thread using runOnUiThread...

Categories

Resources