0

I was curious. Consider I have One SecondActivity with ProgressBar which layout file is

<ProgressBar
    android:id="@+id/progressbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

and In MainActivity I have Two Buttons

<Button
    android:id="@+id/Button 1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/Button 2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Both Button when clicked will open SecondActivity.

Now I would Like to show progress bar when button A is clicked but when Button B is clicked, Make the progress Bar invisible in Second Activity.

Below is diagrams illustrating above method that I would like to get.

Screenshot:

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
nEwyeTi
  • 21
  • 1
  • 3
  • Just pass boolean to second activity . See https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application – ADM Mar 25 '18 at 05:44

1 Answers1

1

You just have to pass some extras along with the intent while launching your second activity.

When button A is clicked, start the second activity like this.

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("SHOW_PROGRESS", true);
startActivity(intent);

And when the button B is clicked, launch the second activity without passing any extra in your intent like the following.

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);

Now from your SecondActivity receive the intent and show the ProgressBar based on the value found from your extras.

boolean showProgressBar = getIntent().getBooleanExtra("SHOW_PROGRESS", false);

if(showProgressBar) progressBar.show();

Hope that helps!

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • I have pbar = (ProgressBar) findViewById(R.id.webViewProgressfaq); on onCreate method , Hence when i used pbar.show(); It gave me error , but instead I sued prab.shown(); and it didn't throwed me any error? does shown() works instead of show()? – nEwyeTi Mar 25 '18 at 17:44