1

I have an activity that calls a second java class. I want after the second class is called to show a progressbar and then return to normal activity execution. I found some other threads but i couldn't make the progressbar to stop.

2 Answers2

3

There's a full example over here.

Quote:

Declare your progress dialog:

ProgressDialog progress;

When you're ready to start the progress dialog:

progress = ProgressDialog.show(this, "dialog title",
    "dialog message", true);

and to make it go away when you're done:

progress.dismiss();

Here's a little thread example for you:

// Note: declare ProgressDialog progress as a field in your class.

progress = ProgressDialog.show(this, "dialog title",
  "dialog message", true);

new Thread(new Runnable() {
  @Override
  public void run()
  {
    // do the thing that takes a long time

    runOnUiThread(new Runnable() {
      @Override
      public void run()
      {
        progress.dismiss();
      }
    });
  }
}).start();

ProgressDialog is deprecated, so you might want to use a ProgressBar.

I've found this post about deleting one of them.

Well, I think this is rather ridiculous, but here is how I fixed it.

In my xml for the ProgressBar, I added android:visibility="gone" to hide it by default. Then, in my code, I first told it to display (View.VISIBLE) before it tried getting the server list, then I told it to hide (View.GONE) after it was done. This worked (I could see the progress indicator while the data loaded, then it went away). So I suppose I couldn't get it to hide in the code because the code is not what forced it to be visible to begin with... That seems like a bug to me.

RubbelDieKatz
  • 1,134
  • 1
  • 15
  • 32
  • Thank you for the hint, @Pavneet_Singh. I'll do some more research and edit my answer. – RubbelDieKatz Aug 29 '17 at 14:11
  • 1
    Thank you this works fine. Suppose i want before dismissing the progress bar to make it visible for additional 20sec (the code runs too fast in localhost) to make the user undestand that something is in progress. How can i do that? – tzimhs panousis Aug 29 '17 at 17:28
  • @tzimhspanousis, this might be something for an additional question. Post your code, too. – RubbelDieKatz Aug 29 '17 at 20:06
  • 1
    Ok. I posted a new question about the delay i was asking to add at https://stackoverflow.com/questions/45955349/how-to-show-progressbar-for-additional-20sec-in-android with the two scripts i need to manage. – tzimhs panousis Aug 30 '17 at 08:21
1

Its very Simple:

to show a Progress

ProgressDialog dialog = ProgressDialog.show(getContext(), "Title", "Message");

and to stop it:

dialog.dismiss();
Rafael T
  • 15,401
  • 15
  • 83
  • 144
  • 1
    `ProgressDialog` has been deprecated, hence `ProgressBar` question – Pavneet_Singh Aug 29 '17 at 14:10
  • 1
    its deprecated? So What? You know that `Thread.stop()` is also deprecated since I've started programming? As long as there are a lot 4.X devices out it'll be guaranteed to still work. – Rafael T Aug 29 '17 at 14:24
  • 1
    `So What?` `Thread.stop()` is also deprecated that's why nobody uses it and it's advisable in android that avoid deprecated version whenever possible and probably most knows about progress dialog start and stop but you can't do the same with progress bar hence the question – Pavneet_Singh Aug 29 '17 at 14:33