When you want to add a second activity in Android Studio, perhaps best way is to do it by using Intent class. Once when you made your first android app as single activity apk, next natural thing is that you want to expand your android application. Good practice is to start your new many activity application as blank activity, and to make other activities as Google AdMob Ads Activity. On that way, first activity would have more space to put some control buttons to it, while later activities would have ads inserted. So late start our blank activity first:
Then you can get rid of the email icon at the bottom of your activity
Just go to appâ†’resâ†’layoutâ†’activity_main.xml and delete four lines of code as indicated in figure bellow.
Also, go to appâ†’javaâ†’cirvirlab.activitiesâ†’MainActivity.java and delete lines of code as indicated in figure bellow.
Next thing to do is to right click on MainActivity.java appâ†’javaâ†’cirvirlab.activitiesâ†’MainActivity.java and add new activity
Advise is to choose Google AdMob Ads Activity so that we have some Google Ads on our second (and later) activities.
This action will make necessary changes appâ†’manifestsâ†’AndroidManifest.xml
Arrange you new activity like any other Google AdMob Ads Activity. Then put one button on your main activity so that you can navigate to second activity. Declare onClik event in text view of content_main.xml
Also, put following code in MainActivity.java file:
public void openSecond(View view)
Button button = (Button)view;
This slice of code shows true power of using Intent class. Second activity appears when you press button.