To call another activity by using an int in an application.

Asked 1 years ago, Updated 1 years ago, 68 views

I have two activities in my project. If you click the first button, the activity starts. If you click the button, I'm trying to end the activity, but nothing happens when I click the button in the first activity. How do I click the button to get a second activity?

public class FirstActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button orderButton = (Button)findViewById(R.id.order);

    orderButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View view) {
        Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
        startActivity(intent);
      }

    });
  }
}

public class OrderScreen extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.order);

    Button orderButton = (Button) findViewById(R.id.end);

    orderButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View view) {
        finish();
      }

    });
  }
}

android android-intent android-activity

2022-09-22 08:40

1 Answers

Please go to the Android manifest.xml file and register your OrderScreen activity. <activity android:name=".OrderScreen" /> This will probably work out.


2022-09-22 08:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.