Difference Between Basic Activity And Empty Activity In Android Studio

When you create android project in android studio, there are a lot of activity templates you can choose which provided by android studio. For android beginners, basic activity and empty activity always make them confused. So what the difference between them, let me tell you now.

1. Create Basic Activity In Android Project.

  1. First you should create an android project. You can read article How To Create New Android Studio Project to learn how to do it if you do not know. You can also input the new project information like below picture.
    create android project
  2. During the project creation process, in Add an Activity to Mobile wizard select Basic Activity template. Then click Next button.
    android blank activity and empty activity
  3. Just click next button in all after wizard and use all default values until complete. Then you can see the basic activity template wizard created files and folders listed in left Project panel.
    basic activity template created files

2. Basic Activity Template Files Introduction.

From above picture we can see that basic activity template create a lot of template files, now we will introduce the most important files below.

2.1 Main Activity Java File.

Double click the MainActivity java class under app / java folder to open it. Please note below java code in onCreate method.


Above code means this activity will use the layout xml file which name is activity_main. You can find the xml file under app / res / layout folder.

2.2 Main Activity Layout Xml File.

Also double click app / res / layout / activity_main.xml file to open it. You can see that it has already contains some android components definition xml.

<!-- AppBarLayout is used to wrap Toolbar to avoid Toolbar is overlapped by other view components.-->

    <!-- This is the Toolbar-->
        app:popupTheme="@style/AppTheme.PopupOverlay" />


<!-- Include the main content layout xml file of this application. -->
<include layout="@layout/content_main" />

<!-- This is the floating action button which float over the screen. -->
    app:srcCompat="@android:drawable/ic_dialog_email" />

At the top of the layout xml is a Toolbar wrapped by AppBarLayout. AppBarLayout is used to wrap Toolbar to avoid Toolbar is overlapped by other view components when screen scroll. Please refer article Android AppBarLayout And Toolbar ExampleAndroid Material Design Toolbar Example.

After that is a include xml tag. This tag will include the activity content layout xml file which is named content_main.xml. This xml file is also saved in app / res / layout folder.

At the layout file bottom is a floating action button. This button is introduced in android material design. It is a button floating over the screen. You can read How To Avoid Snackbar Overlap Floating Action Button In Android for detail introduction.

2.3 Activity Content Layout Xml File.

Now open content_main.xml file under app / res / layout folder, this file is the place where you design your app UI. The template content is too simple, there is only one TextView component in it.

Click Design tab under it, you can drag and drop a lot of android ui components into it visually. You can also click the Text tab at bottom to see the layout xml code.

In the xml designer Palette area, all android ui components is classified by type, click each type will list the components under it. Under the Palette is Component Tree, that list all this app’s ui components in a tree, you can easily adjust the ui components order and relationship in it.

android layout xml file designer

There is also a toolbar in the android layout xml file designer. Use this toolbar you can look and feel your design instantly with following actions.

android layout designer toolbar

  1. Change the screen direction to Portrait or Landscape.
  2. Show your design effect in multiple devices.
    change layout xml display device
  3. Check ui effect by changing android API version.
    change android api version to check layout effect
  4. Change the activity theme. The activity theme decide how this activity looks and feel. It is used in the application AndroidManifest.xml file, we will introduce it later.
    change android app theme to see layout effect
  5. Change app language.

3. Create Empty Activity.

  1. Right click the java package, click New —> Activity —> Empty Activity menu item in popup menu list.
    create new android activity
  2. Just click Finish button and use all the default values. When the process complete, you can see that there is only one activity java file and one layout xml file.

Now we can tell that the difference between basic activity and empty activity is basic activity create a best practiced standard code skeleton for android developer but empty activity just create an activity java and layout xml file.

4. The Android Application Manifest File.

All the activities is just act as components in android app, one android app can contains multiple activities. But how to assemble all these activities together to make a complete android app. We use AndroidManifest.xml file to do this.

This file is so important for android app, it is saved in app / manifests folder.

android manifest xml
Open this file you can see below xml code. From the xml code, we can get below results.
  1. This android application contains two activity.
  2. Application and activity can use different theme. The theme are defined in app / res / values / styles.xml file.
  3. Application and activity label is string variable defined in app / res / values / strings.xml file. This is a good habit than hard coding string value in source code, this can make your app internationalization.
  4. App icon value is also reference a variable defined in app / res / mipmap folder.
  5. Specify MainActivity as the launcher activity by intent-filter category value.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
        <activity android:name=".Main2Activity"></activity>



5 1 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Oldest Most Voted
Inline Feedbacks
View all comments
Michael Halper
Michael Halper

In Android Studio (AS) 4, a Basic Activity is now created, by default, with a pair of fragments. Questions: (1) can this fragment-creation be eliminated? (2) Is this new default behavior of AS implying that a Basic Activity’s interface be defined as a “main fragment”? (3) Even if the answer to (2) is yes, why is it necessary to always get the second fragment created for you? (4) Again, assuming a yes answer to (2): where do the interface callback (e.g., button callbacks) reside, in the activity’s Java file or the fragment’s Java file.


So, what does an empty Activity look like?

Gavin Ayling
Gavin Ayling
Reply to  Johan

It’s literally empty. It has an empty blueprint that you can place components onto.

Would love your thoughts, please comment.x