How to create new activity in android studio
To create a new activity in Android Studio, follow these steps:
Method 1: Using the "New Activity" Wizard
- Open your Android project in Android Studio.
- In the project structure, navigate to the
app
directory. - Right-click on the
app
directory and select "New" > "Activity" > "Empty Activity". - Fill in the required information:
- Activity name: Enter a name for your activity (e.g., "MainActivity").
- Package name: Leave this field blank, as it will be automatically generated.
- Save location: Choose a location to save your activity (e.g.,
app/src/main/java/com/example/yourapp
). - Language: Select the programming language you want to use (e.g., Java or Kotlin).
- Click "Finish" to create the new activity.
Method 2: Using the "New" Menu
- Open your Android project in Android Studio.
- Go to the "File" menu and select "New" > "Activity" > "Empty Activity".
- Fill in the required information (same as above).
- Click "Finish" to create the new activity.
What happens next:
After creating the new activity, Android Studio will generate the necessary files and folders for your activity. You will see a new directory created under app/src/main/java
with the same name as your activity (e.g., MainActivity.java
or MainActivity.kt
).
Tips and Variations:
- You can also create a new activity using the "New" menu and selecting "Other" > "Activity" > "Blank Activity" or "Other" > "Activity" > "Navigation Drawer Activity" (for a navigation drawer-based activity).
- If you want to create a new activity with a specific layout or theme, you can select the corresponding options in the "New Activity" wizard or menu.
- You can also create a new activity by copying an existing activity and modifying it to suit your needs.
That's it! You now have a new activity in your Android project.