There are some ways to declare a new activity in android. But in this section, I just want to describe an simplest way to do it.
– Open the AndroidManifest.xml file then follow below steps to add new activity.
– Look at the Attributes for Activity section at right side, click Name to create a new class or Browse to choose an existing class. This class will contain code-behind of this activity and it must inherit from Activity class under android.app.Activity namespace. Also you can configure other properties for you activity such as orientation, theme, label…
– Right click on Layout folder, choose new > Android XML File. In the new Android XML File dialog, type the class name then hit button Finish. Note that the layout file name must end with “.xml” and just contains a-z, 0-9 character.
– Open MyActivity.java file, edit the OnCreate method as below image.
Now, whenever MyActivity is invoked, it load the myactivity.xml layout to the screen.