Create new empty activity in android studio

Here's a step-by-step guide to create a new empty activity in Android Studio:

Method 1: Using the "New Activity" Wizard

  1. Open Android Studio and create a new project or open an existing one.
  2. Click on the "File" menu and select "New" > "Activity" > "Empty Activity".
  3. In the "New Android Activity" dialog, enter the following details:
    • Activity name: Enter a name for your activity, e.g., "MyActivity".
    • Package name: Enter the package name for your activity, e.g., "com.example.myapp".
    • Save location: Choose the location where you want to save your activity, e.g., "app/src/main/java".
    • Language: Choose the programming language for your activity, e.g., "Java" or "Kotlin".
  4. Click "Next" to proceed.
  5. In the "Configure Activity" dialog, choose the following options:
    • Activity type: Select "Empty Activity".
    • Minimum SDK: Choose the minimum SDK version for your activity.
    • Theme: Choose a theme for your activity, e.g., "Light" or "Dark".
  6. Click "Finish" to create the new activity.

Method 2: Using the "New" Menu

  1. Open Android Studio and create a new project or open an existing one.

  2. Click on the "File" menu and select "New" > "Java Class" (or "Kotlin Class" if you're using Kotlin).

  3. In the "New Java Class" dialog, enter the following details:

    • Class name: Enter a name for your activity, e.g., "MyActivity".
    • Package name: Enter the package name for your activity, e.g., "com.example.myapp".
    • Save location: Choose the location where you want to save your activity, e.g., "app/src/main/java".
  4. Click "OK" to create the new activity.

  5. In the "MyActivity.java" (or "MyActivity.kt") file, add the following code:

    public class MyActivity extends AppCompatActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_my);
     }
    }
  6. Create a new layout file for your activity by right-clicking on the "app/src/main/res/layout" directory and selecting "New" > "Layout resource file".

  7. Name the file "activity_my.xml" and add the following code:

    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
    
     <TextView
         android:id="@+id/textView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Hello World!" />
``` That's it! You now have a new empty activity in Android Studio.