MrAnderson1992 MrAnderson1992 - 1 year ago 36
Java Question

Open same activity with different result. From MainActivity

I am wondering if it is possible to open a new activity but with different results depending on which button has been pressed. For example:

Main Activity -

Pressing any of these buttons would take you to "FruitInfoActivity" however, depending on the button pressed would give you a different text view of say a description of the fruit.

The alternative is to have a new activity for every single fruit, which as an example would be a lot of activities.

Any help would be great thanks.


You can pass information in the intent you create for starting the new activity.

Intent intent = new Intent(getBaseContext(), FruitInfoActivity.class);
intent.putExtra("FRUIT_NAME", "Apple");

And you can get this information in new Activity (FruitInfoActivity) to show it in your text field.