Activity is a very important component in android application development. It represent a screen which is used to interact with phone user. Commonly there are three important files for create and use an activity: a xml layout file, a java class file and AndroidManifest.xml.
- The xml layout file is used to design the app’s UI part. We can think it as View role in MVC design pattern.
- The java file is used to manipulate layout file, listen and process user action, startup other activity to user when needed. So we can think it as Control role in MVC degisn pattern.
- AndroidManifest.xml : We config all activitys in this xml file. You can also specify activity attributes such as set one activity as android app startup activity in this file.
1.How To Create One Activity In Android Studio.
- First make sure you have selected the Project view’s Android sub view.
- Then right click app folder in Android view, click ” New —> Activity ” menu. There will list some activity template menu, you can select the one you need. In this example, we select Empty activity.
- Then the Configure Activity window will popup. You can input or modify activity name and layout name as you need. Commonly the layout name has under line in it to separate English words. You can check Launcher Activity checkbox to make it as the android application startup activity.
- Click Finish button to complete the activity creation process. After that you can see the three core files in project view at left panel.
In this example AndroidManifest.xml is located in app / manifests folder. ButtonListenerExampleActivity java file is located in app / java folder. activity_button_listener_example.xml is located in app / res / layout folder.
- Then you can double click above file to write code in it. If you want to learn more detail about above three files, you can read article Android Hello World Example Project File Structure or Android Studio Button Listener Key Listener And Browse Url Example.