Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
22 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Anoja
4 years ago

Go to run->edit configurations->Launch Options -> Activity change your appropriate activity after did the above changes.

Vimal J. Goyal
9 years ago

Hahahahahahahaha. good try, but not working

jike
5 years ago
Reply to  Vimal J. Goyal

ooooh nooooo…….

gavieC
10 years ago

Thanks. Concise and Informative post.

jemblok 333
7 years ago

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

Stars Halcombe
8 years ago

How do I do this on my rca table

Philip Jeffrey Trowe
8 years ago

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
8 years ago

you suck.

obert
9 years ago

Thank you, amazing little tutorial, worked first time!

Jbal Tero
9 years ago

This works for me thank you.

IrvineCAGuy
9 years ago

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

Khanh Nguyen
9 years ago

Sr, if I have 2 plugin and two plugin conflict

What shoud I do to fix it?

louis vuitton ?????
10 years ago

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

louis vuitton ?? ??
10 years ago

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

louis vuitton ??? ??
10 years ago

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

louis vuitton ?????? ???
10 years ago

louis vuitton antico

???? ??
10 years ago

? ???? ?

?? ???? ??
10 years ago

louis vuitton ?? ??

check this out
10 years ago

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

Ragavi
11 years ago

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

Jason
11 years ago

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
12 years ago

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 ?