Custom ProgressBar not spinning, when open from onResume() - android

I have a custom progress bar in my app. When I open my app, this Custom ProgressBar works well, but in some situations where my app calls itself, the onCreate() event does not called.
The app starts from an onResume() event. I have created a function to open the progress bar that is called in the onResume() event. The problem is that the custom Progress Bar gets opened but does not start SPINNING, and it is dismissed after the task is completed. It therefor appears as if the application is hanging.
Are there any solution for this?

Related

Updating Custom listview item after on resume()

I have a custum listview with image, text, a download button and a progress bar for each item.
The plan is that when I click the download button, the progress bar which original is invisible becomes visible and starts to progress, while the download button changes to a cancel button.
But what happens now is that when I minimize the app to home and opens it back up, the listview refreshes(that is the adapter is called again) as the activity resumes. This undos all the states which have been set.
the progress bar becomes invisible and the download button shows up with the download icon instead of the cancel icon, even though the download continues in Asynctask.
What I need to do is to find a to set the state of the list item, such that the progress bar continues to progress and the button changes to cancel button. i.e to retain the ui state as the download goes on in the Asynctask, even when the listview is reinitialized.
I viewed` your question. The problem is regarding the Asynchronous AsyncTask that you used. I can try to explain you the problem and the recommended solution.
If you start the AsyncTask inside your activity, Now when you close the activity (finish) It is not guaranteed that the running AsyncTask also stop working and finish itself because of your activity is no longer running. That does not happen.
Another fact is that, As previously said that once you fire the AsyncTask you could not reuse it next time when you start the same activity again. In your case, it always starts the new AsyncTask when you open the activity.
Alternative Solution: You can use the Service component that can run in the background (keep in mind that it does not create the separate thread from your application, It's run on the application thread) means it has no UI and could be run even if your activity or application is not in front of the user. You can put your download logic inside it and bind with your running activity.
Regarding the state of the UI in adapter that you can manage by communicating between the activity and running service.
This is simple approach that you can use it.
Hope this will help!
Thanks
Bhavdip

ProgressBar won't show when I call setVisibility(View.Visible)

In an Android app, I am trying to make a ProgressBar visible when a button is clicked, conduct some processes, and then make the bar invisible again. A general overview of my button's onClick method is shown below:
ProgressBar bar = (ProgressBar)findViewById(R.id.prog_bar);
bar.setVisibility(View.VISIBLE);
...do some stuff...
bar.setVisibility(View.INVISIBLE);
However, when I run the code, while the process in the middle is completed, the ProgressBar never shows up. Any ideas?
OnClick is called on the main thread. Your changes to the ProgressBar will not have any visible effect until your OnClick method returns. By that time, you've already finished all your work and hidden it again.
Move your work to a background thread. Not only will this make your app more responsive, it will allow the prograss bar to appear. (Note that, when your work is finished, you'll have to hide the progress bar from the main thread, not the worker thread. Typically you post a Message to a Handler to achieve this.)

Android indeterminate progress bar between activities

How to get an indeterminate progress bar between two activities, I mean, I'm in activity A, show the progress bar, while the progress bar is showing, a new activity B is started and in this activity B I want to close the progress bar. Thank you.
You can't do it that way. An Activity is what holds everything on the screen for your application. If you are "inbetween" two activities then you have no way to control what is on the screen.
You need to put the progress bar into ActivityB, and make it visible by default, then when you are done loading your data make it invisible with
progressBar.setVisibility(View.GONE);
If your ActivityB is taking a long time to load before showing any Views then it is an indication that you are doing some loading work on the Main thread, that you should isntead be doing in the background, and updating the Views once loading is complete.
There is no reason to do so. Starting a new activity is a very fast process, almost instant (unless you onPause method takes very long), so the progress bar will never be shown.
That being said, there is a hacky way to get a progress bar to be shown between activities
you call ProgressActivity(that you create) from ActivityA then after waiting for some time (delayed runnable) you call ActivityB. This does nothing constructive and should not be used.

disable touch focus while loading

I have an android app that uses a glSurfaceView that takes a few sections to load up.
I have onTouchEvent overridden, and I'm trying to disable focus while it loads but setFocusable(false) isn't working.
The problem is if the user taps on the screen before everything loads, the app gets a null and it crashes.
I'd pop up a progress dialog and use an AsyncTask to do the loading of the view. Once the view is loaded you can kill the dialog. Any heavy lifting should not be done on the UI thread anyway.

Android - Indeterminate ProgressBar

I am using the code from this website (http://www.helloandroid.com/tutorials/using-threads-and-progressdialog) in my App.
It is somewhat working, but not entirely:
When I press Button X, a method is called, and while it is working, the progress bar is shown. After the method is done, another activity is started. So far everything is working fine. But when I press the "BACK" button on my phone, the progress bar is shown again, and appears to be doing nothing.
What can I do to prevent that?
Dismiss the progress bar at the same time that you start the second activity.

Categories

Resources