It would be nice if the ProgressBar could be made to go away until it is needed. Is there a problem using setVisibility.progressBar in applyMenuChoice? The problem with using setVisibility.progressBar in PrintStatusTask().execute() is that it crashes the app during runtime.
public class Controller extends Activity {
private ProgressBar progressBar;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.controller);
progressBar = (ProgressBar)findViewById(R.id.progressBar);
...
private boolean applyMenuChoice(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuStatus:
progressBar.setVisibility(View.VISIBLE);
new PrintStatusTask().execute();
progressBar.setVisibility(View.GONE);
...
progressBar.setVisibility(View.VISIBLE);
new PrintStatusTask().execute();
progressBar.setVisibility(View.GONE);
This is what you are doing: 1. Show the progressBar 2. Spawn a task on a separate thread 3. Hide the progressBar
This entire process is going to take no more than a couple milliseconds to execute. You need to hide the progress bar in the onPostExecute()
method of the PrintStatusTask class.
You need to understand that the execute()
method of AsyncTask is a call that executes another thread and doesn't wait for it to finish. That's kind of the whole point of AsyncTask.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With