I have a progress bar that I change from View.GONE
to View.VISIBLE
, just before I call a method writeFile()
.
Something like this:
onButtonPress(){
mProgressBar.setVisibility(View.VISIBLE);
writeFile();
}
The method writeFile()
can take a few seconds (lots of data parsing), but requires additional actions taken by the user afterwards, and thus is not performed on a background thread. This is to avoid the user navigating elsewhere within the app, and then being presented with a pop-up, or redirected, for something they thought they were done with.
My problem is that the Progress Bar does not display until the writeFile()
method is complete, and then briefly pops up for a split second before the user is redirected elsewhere.
If I comment-out the method call, then the ProgressBar appears immediately and spins indefinitely, so I know the bar is working properly.
How can I ensure the progress bar pops up FIRST, and then the writeFile()
method is called after?
Thanks in advance.
Additionally:
I don't have a lot of experience (exactly none!) with asynctasks, and so am not sure if this is the route I need to take. The behaviour I am looking for is the progress bar to pop up when the user presses the button, and remain on the screen until the method is complete. I don't want the user to navigate around the app during this time.