Android Progress bar not hiding [duplicate]
I have a dashboard section in my android application where once a user clicks on a button, a preogressDialog is show ("Please Wait") and the next开发者_如何学JAVA activity loads up. But when i click the android device bacj button, the progress bar is still showing up. I used dismiss() but to no use. Any help is appreciated.
progressDialog.setMessage("Please wait...");
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(true);
progressDialog.show();
browseCategories();
protected void browseCategories() {
Log.i(MY_DEBUG_TAG, "Bow!");
Intent c = new Intent(this, CategoryListActivity.class);
c.putExtra("user", u);
startActivity(c);
}
Using a progress dialog in an activity immediately before starting another one doesn't make sense.
Activities are, for the most part, meant to be UI-oriented and when one starts another then the new one is 'layered' over the top of the first.
If the CategoryListActivity is going to take some time before it is ready for use (loading data for example), then it should show a progress dialog and not the activity that starts it. Using an AsyncTask for loading data or any operation which will take an extended time is the best way to proceed.
I suggest you read about Application Fundamentals and the Activity Lifecycle
in layout XMl file :
<ProgressBar
android:layout_marginTop="60dip"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prgressbar"
android:visibility="invisible"
/>
in Onclick event of button do this:
ProgressBar prgressbar;
prgressbar=(ProgressBar)findViewById(R.id.prgressbar);
prgressbar.setVisibility(LinearLayout.VISIBLE); // this of visible the progress bar
prgressbar.setVisibility(LinearLayout.INVISIBLE); // this is for invisible
精彩评论