Android studio how to create new activity
To create a new activity in Android Studio, follow these steps:
- Open your project in Android Studio.
- In the Project panel, right-click on the app folder (or the package name) and select "New" > "Activity" > "Empty Activity".
- In the "Create New Activity" dialog box, select the following options:
- Activity type: Empty Activity
- Language: Java (or Kotlin, depending on your preference)
- Name: Enter a name for your activity (e.g., "MainActivity")
- Package name: Leave this field blank
- Save location: Choose a location to save your activity (e.g., "app/src/main/java")
- Click "Finish" to create the new activity.
Android Studio will create a new Java or Kotlin file for your activity, along with a corresponding XML layout file. The activity will be added to your project's manifest file (AndroidManifest.xml).
Here's a breakdown of the files that Android Studio creates:
MainActivity.java
(orMainActivity.kt
): This is the Java or Kotlin file that contains the code for your activity.activity_main.xml
: This is the XML layout file that defines the user interface for your activity.AndroidManifest.xml
: This is the manifest file that declares your activity and other components of your app.
You can customize the activity by modifying the code in the Java or Kotlin file, and the layout in the XML file. You can also add additional files and resources to your activity as needed.
Note: If you want to create a new activity with a specific template (e.g., a list activity or a fragment activity), you can select the corresponding option in the "Create New Activity" dialog box.