Android Development Starter Guide using Android Studio
Moving from One Activity to Another



Step 1:
Create a button in your Main Activity.  Refer to the tutorial on Creating a Functional Button. Link

Step 2:
Add in the onClick method into your button.  Lets call it nextActivity.

Step 3:
Add in the nextActivity method in the MainActivity java file.  This method will have to take in a View object.

//In MainActivity.java
public void nextActivity(View view){
//Code to input later
}


Step 4:
We are going to create another activity.  File->New Activity->Blank Activity .  Will use the default name MainActivity2Activity.


Step 5:
Going back to MainActivity, we will write code in the nextActivity method to move to the MainActivity2Activity screen.  See the comments in the code to see what's going on.

//In MainActivity.java
public void nextActivity(View view){
//The Intent class is used to store information passed from one
//activity to another. When instantiating it, you will need to
//put in the Activity class you want to move to. You can put
//in data to pass through as well. See the tutorial on Passing
//Data From One Activity to Another
Intent intent = new Intent(this, MainActivity2Activity.class);

//This method will start another Activity given the intent
startActivity(intent);
}

Step 6:
Run the code. Click the button in MainActivity. It should move from the MainActivity page to MainActivity2Activity.



to