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. Go to run->edit configurations->Launch Options -> Activity change your appropriate activity after did the above changes.

    Reply
  2. Help me please..
    how to android application no imprint on the new application is opened (recent app)? .xml what changed?

    Reply
  3. 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

    Reply
  4. Hahahahahahahaha. good try, but not working

    Reply
  5. I’m using Android Studio 0.82 and setting intent-filter is NOT working for me.

    Reply
  6. Sr, if I have 2 plugin and two plugin conflict

    What shoud I do to fix it?

    Reply
  7. Wow, this paragraph is good, my sister is analyzing
    these kinds of things, therefore I am going to convey
    her.

    Reply
  8. hi..could you please explain how to get multiple screen support for my android app???

    Reply
  9. 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

    Reply
  10. 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 ?

    Reply

Leave a Comment

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