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>

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Vimal J. Goyal
Guest
Vimal J. Goyal

Hahahahahahahaha. good try, but not working

jemblok 333
Guest
jemblok 333

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

Stars Halcombe
Guest
Stars Halcombe

How do I do this on my rca table

Philip Jeffrey Trowe
Guest
Philip Jeffrey Trowe

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

Joris Neber
Guest
Joris Neber

you suck.

obert
Guest
obert

Thank you, amazing little tutorial, worked first time!

Jbal Tero
Guest
Jbal Tero

This works for me thank you.

IrvineCAGuy
Guest
IrvineCAGuy

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

Khanh Nguyen
Guest
Khanh Nguyen

Sr, if I have 2 plugin and two plugin conflict

What shoud I do to fix it?

louis vuitton ?????
Guest
louis vuitton ?????

??? ??,?? ????? ??

louis vuitton ?? ??
Guest
louis vuitton ?? ??

??? ??,?? ????? ??

louis vuitton ??? ??
Guest
louis vuitton ??? ??

??????????????

louis vuitton ?????? ???
Guest
louis vuitton ?????? ???

louis vuitton antico

???? ??
Guest
???? ??

? ???? ?

?? ???? ??
Guest
?? ???? ??

louis vuitton ?? ??

gavieC
Guest
gavieC

Thanks. Concise and Informative post.

check this out
Guest
check this out

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

Ragavi
Guest
Ragavi

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

trackback
Android Tutorial

[…] How to set default activity for Android application […]

Jason
Guest
Jason

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

Ankush Agarwal
Guest
Ankush Agarwal

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 ?