Create new activity android studio
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 module (usually named "app") and select "New" > "Activity" > "Empty Activity".
- In the "Create Activity" dialog, 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 (it will be automatically generated)
- 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 will be created:
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 now modify the code and layout files to customize 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 Activity" dialog.