-1

I've seen a few other questions similar to this, but I still cant seem to get an answer.

What I would ideally like is to use the intent method as shown below to switch to another activity.

Here is my MainActivity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
public void sendCalc (View view){
    Intent intent = new Intent (this, MainActivity.class);
    startActivity(intent);
}

and this is my second activity: {

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

    Intent intent = getIntent();
}

and here is my xml file for the button.

 <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/createCalc"
        android:onClick="sendCalc"
        android:elevation="2dp" />

Also, I have added the second activity in the manifest file.

Thank you in advance for the help.

Neo
  • 3,309
  • 7
  • 35
  • 44

1 Answers1

0

I'm gonna give you an example of one of my app's code to change to the next activity

NextPage = (Button)findViewById(R.id.button);

    NextPage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent (MainActivity.this, Main2Activity.class);
            startActivity(intent);

        }
    });

You put this over the:

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