How to set default activity for Android application

In Android, you can configure the starting activity (default activity) of your application via following “intent-filter” in “AndroidManifest.xml“.

See following code snippet to configure a activity class “logoActivity” as the default activity.

File : AndroidManifest.xml


        <activity
            android:label="Logo"
            android:name=".logoActivity" >
             <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

For example, let said you have two activities class, and you want to set the “ListMobileActivity” activity as the starting activity of your application.

File : AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mkyong.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="List of Mobile OS"
            android:name=".ListMobileActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="List of Fruits"
            android:name=".ListFruitActivity" >
        </activity>
    </application>

</manifest>

On the other hand, If you want to set the “ListFruitActivity” activity as your starting activity, just cut and paste the “intent-filter” like following :

File : AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mkyong.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="List of Mobile OS"
            android:name=".ListMobileActivity" >
        </activity>
        <activity
            android:label="List of Fruits"
            android:name=".ListFruitActivity" >
             <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

22 comments on “How to set default activity for Android application

  1. Why not take a look at my blog about how to create an Android app that displays an Image in an ImageView control of the main Activity at the full width of the screen.

    The app uses the following Android SDK objects:

    . ImageView
    . LinearLayout
    . Bitmap
    . Activity
    . XML layout
    . LayoutParams
    . Display

    Also:
    . layout_height
    . layout_width
    . orientation
    . id
    . vertical
    . match_parent

    XML attributes and values are covered.

    Click the link BELOW! to see

    http://androidprogrammeringcorner.blogspot.com/2015/06/pak-longs-android-programming-corner.html

  2. Hi,
    It’s a nice post. Btw, could you explain how to create 2 default activities in androidmanifest which allow 2 activities runs on app start?

    Thanks

  3. Hi,
    Thanks for the helpful tutorial. Could you tell me if there is a way to get the default application for an implicit intent(after you have set some app as default). For example if somebody sets Opera browser as default app for implicit intents for opening websites, is there a way to programatically figure this out ?

Leave a Comment

Your email address will not be published. Required fields are marked *