Start New Activity When Button is Clicked in Android
https://www.viralandroid.com/2015/10/start-new-activity-when-button-is-clicked.html
In this example, I will show how to start a new activity(new screen) when a button is clicked in android application. Here, if you click the click me button, you will see the new activity(second activity).
Related:
How to Change Android Button on Click/Press Color
How to Set Android Button and TextView Border Color
How to Add Ripple Effect/Animation to a Android Button
XML Layout File
Add the following xml code in your activity_main.xml file.
res/layout/activity_main.xml
Now, create a new xml layout called activity_second.xml and add following.
res/layout/activity_second.xml
Java Activity File
Following is the java code of MainActivity.java file.
src/MainActivity.java
Again, create a new java file called SecondActivity.java and add following code.
src/SecondActivity.java
AndroidManifest.xml File
Following is the final code of AndroidManifest.xml file.
Now, run your application and click the click me button, you will see the new activity.
Related:
How to Change Android Button on Click/Press Color
How to Set Android Button and TextView Border Color
How to Add Ripple Effect/Animation to a Android Button
XML Layout File
Add the following xml code in your activity_main.xml file.
res/layout/activity_main.xml
Now, create a new xml layout called activity_second.xml and add following.
res/layout/activity_second.xml
Java Activity File
Following is the java code of MainActivity.java file.
src/MainActivity.java
Again, create a new java file called SecondActivity.java and add following code.
src/SecondActivity.java
AndroidManifest.xml File
Following is the final code of AndroidManifest.xml file.
Now, run your application and click the click me button, you will see the new activity.
![]() |
Start New Activity |