Shashika
Shashika

Reputation: 1636

Handle a progress dialog in multiple activities

In my project, I need to start a progress dialog in one activity and need to stop it in an another activity. Here is my code.

progress.setMessage("Searching... ");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.setIndeterminate(true);
progress.show();
Intent intent = new Intent(mContext,BirdsAlgorithm.class );
intent.putExtras(bundle);
startActivity(intent);

I need to stop this progress bar in BirdsAlgorithm class. How can I do this?

Upvotes: 1

Views: 729

Answers (2)

Hafiz.M.Usman
Hafiz.M.Usman

Reputation: 231

You have two options:

  1. make progress static and public and then in next activity access it through the class name and then stop it.

  2. override on destroy and on stop method for activity and then on stop and on destroy stop your progress

Upvotes: 0

Nabin
Nabin

Reputation: 11776

The progress dialog runs on UI thread. So you should not do anything like this. Instead you can dismiss the progress and start a new instance of it in new Activity.

Upvotes: 1

Related Questions