-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.

3
  • What is the name of second activity? Is MainActivity the second activity which you want to start? Intent intent = new Intent (this, MainActivity.class); Commented Nov 15, 2016 at 17:20
  • @ShobhitPuri the second activity is called calculation Commented Nov 15, 2016 at 18:11
  • So instead of MaijActivity.class use the second activity name Commented Nov 15, 2016 at 18:12

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

13 Comments

sorry, this might be stupid , but what does NextPage stand for
I just get a whole lot of errors
You need to have a button to do a OnClick intent "NextPage" is the Button name in the MainActivity.class
You need to create another activity so it can move to there else you wont get anything from this code
I have another activity its called calculation. here is it in full:
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.