Search code examples
androidandroid-activityonclicklistener

Change text content depending on button clicked within the same class


My problem is exactly like this link but it's not in android.

I have one button on a layout and two buttons on an another one. On my application, ClickScreen activity can be triggered by either FirstCase activity or SecondCase activity.

I tried to make a conditional statement on my ClickScreen for which activity is triggered but couldn't handle it. I don't want to create two more classes to do this since it's not an efficient technique.

private void goTo2ndPage() {
    Intent i3 = new Intent(this, ClickScreen.class);
    startActivity(i3);
}

public class ClickScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.click_screen);

    }
}

Solution

  • As we discussed in comments. It looks like what you really want is to add extra data in your intent so that Started Activity can get it and act accordingly.

    Check out this post !