Ok so. I want to set a progress bars visibility to VISIBLE when I am pressing a button for example... and then I want to set the visibility to GONE when I am resuming the same activity.
at the same time as loading other data if possible.
Here is what I am trying:
public void onPause(){
super.onPause();
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
}
and
Button aButton = (Button) findViewById(R.id.abutton);
aButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
Intent i = new Intent("org.packagename.etc.etc");
startActivity(i);
}
});
but it doesn't work because when I click the button it doesn't show the bar it just jumps straight to the activity (which loads data so takes a few seconds). So it needs to be threaded or something?
halp meh!
The problem here(If i am right) is that the progress bar is a part of the activity you are currently running, and you want to show it while another activity ("org.packagename.etc.etc") is doing some work?
If that is the case, you should start the progress bar in the activity that does the work. But that by itself will not work either. You have to do the work in a seperate thread! You should look into using an AsyncTask for the data loading.
This tutorial might help you with that. http://www.vogella.de/articles/AndroidPerformance/article.html
When you start a progress bar, it runs on the UI thread, but if you also do your work on the UI thread, it will not display the progress bar until the other work is finished. And by then, you will most likely already have hidden the progress bar again.