This question already has an answer here:
Android Progress Bar is not dismissed
(1 answer)
Closed 8 years ago.
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 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
Related
I have a bottom navigation view, and this view has 3 items 3 different fragments.
In my one fragment I am uploading a video file to server.
My question is :
When upload start I want to show uploading progress from my main activity like instagram doing.
How can do this ? any advice please
ProgressDialog pd=new ProgressDialog(context);
pd.setMessage("Your Message");
pd.show(); //Where you want to show PD
pd.dismiss();// where you want to Dismiss PD
I'm trying to show my Indeterminate Progress Indicator When a certain Card is being tapped.
I declared the indicator in my onCreate as follows
mSlider = Slider.from(mCardScroller);
mIndeterminate = mSlider.startIndeterminate();
Then in my onclick I have the following
mIndeterminate.show();
intent = new Intent(getApplicationContext(), CaptureActivity.class);
startActivityForResult(intent, REQUEST_CODE);
I want to show the progress indicator while the QR-Scan activity is being loaded since this takes a few seconds.
However with this the indicator doesn't show up at all. Is there a way to make sure the indicator is being shown while the called upon activity is loading?
When I take out the startActivityForResult() it does start the indicator so I'm pretty sure it has something to do with the lifecycle of the activity, but I'm not sure how I should go about it in this case.
I guess you should put the slider in CaptureActivity instead.
Your slider is hidden. From my understanding, you start the progress bar in the activity which is moved to the background. The whole activity cannot be seen not only the progress bar.
Try moving these code into onCreate of CaptureActivity
mSlider = Slider.from(mCardScroller);
mIndeterminate = mSlider.startIndeterminate();
mIndeterminate.show();
I am using progress bar for displaying status of data download from server using AsynkTask.
I have written a callback method from which I update the progress
#Override
public void onBookDownloadProgressUpdated(int value)
{
if(_bookProgressBar == null)
{
LinearLayout linearLayout = (LinearLayout) latestLinearLayout.findViewWithTag(layoutTagQueue.peek());
_bookProgressBar = (ProgressBar) linearLayout.getChildAt(1);
}
_bookProgressBar.setProgress(value);
}
This works fine.But when user goes to another screen and coming back to that screen then the progress bar didn't show any progress while the downloading is going on in the background.
how to show current progress even user press the back key and revisit that screen.
Try using below link for progress bar and put the method which will set the value of progress bar in onResume() instead of onCreate() or onStart().
Use a static variable(int) for showing the progress of progressbar.
Download a file with Android, and showing the progress in a ProgressDialog
Is it possible to show progress bar when switching from activity to another.please help me
You will have to show the progress bar in the second activity because the first activity will be hidden and wouldn't show up anyway.
try this!!!!
ProgressDialog pd = new ProgressDialog(FirstActivity.this);
//use this before calling intent
pd.setMessage("Processing...");
pd.show();
//call this in onResume of firstActivity
pd.dismiss();
I've searched everywhere and I can't find a solution to this problem.
Basically I have a login screen and I'm trying to get a progress spinner to show up while it's logging in to the server (via a thread), and then dismiss it after the login is successful. It has to work while changing orientations.
I am using DialogFragment with the Android compatibility package to make a progress bar (can't find any documentation on it, only for basic\alert dialog) because showDialog() is deprecated now. Right now I just show a custom message box as a login spinner.
In Summary:
How can I set up a Progress spinner with DialogFragment.
How can I dismiss it in another thread after orientation changes.
For showing a progress spinner, just override DialogFragment.onCreateDialog() in your dialog fragment like this (no need for overriding onCreateView()):
#Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final ProgressDialog dialog = new ProgressDialog(getActivity());
//
dialog.setTitle(R.string.login_title);
dialog.setMessage(getString(R.string.login_message));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
// etc...
return dialog;
}
As for dismissing that dialog fragment from somewhere else, you'll need to get a hold of FragmentManager (from inside your next FragmentActivity or Fragment) and call popBackStack() on it (if you don't do any other fragment transaction in the meantime).
If there's more steps/fragment transactions between your progress dialog fragment and the next activity, you'll probably need one of the other popBackStack(...) methods that take an ID or tag to pop everything up to your progress dialog fragment off the stack.
I know this is old question but I want to share much better solution for this
According to Android Development Protip:
"Stop using ProgressDialog,Inline indicators are your friend"
As Roman Nurik states:
This one's quick. Stop using ProgressDialog and other modal loading
indicators. They're extremely interruptive and annoying, especially
when:
You see one every time you switch tabs.
You can't Back out of them.
They say "Please wait." No thanks, I'd rather just uninstall.
Either show loading indicators inline with your content (e.g.
http://developer.android.com/training/animation/crossfade.html) or better yet, load small amounts of data in the
background so that you minimize the need to even show a loading
indicator.
More about progress & activity in the design guidelines.