Android – New Activity on Click Button

Step 1. Create a new empty project in Android Studio and Go to File:-New Project and fill all require fields to create a new project.
 
Step 2. Copy & paste these below code into res=>layout=>activity_main.xml.


   
Step 3. Goto src=>MainActivity.java file and copy & paste below code into MainActivity.java file.
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
   Button button;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      button = (Button) findViewById(R.id.button);
      button.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            openNewActivity();
         }
      });
   }
   public void openNewActivity(){
      Intent intent = new Intent(this, NewActivity.class);
      startActivity(intent);
   }
}
Step 4. Now Create new empty activity in exist project and paste the following code into res=>layout=>activity_new.xml.


   
Step 5. Paste the following code into src=>NewActivity.java.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class NewActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_new);
   }
}
Step 6. Now goto AndroidManifest.xml file for giving the permission for new open activity and paste these below code into AndroidManifest.xml.





  
        

        
  




Step 7. Now connect your Android Mobile device with Android Studio for checking output of application. Open one of your project’s activity files and click Run icon from the toolbar.

new Activity on click button

new Activity on click button