442

I have created the meat and guts of my application but I want to add a different activity that will be the starting point (sort of a log-in screen).

Couple questions:

  • 1 I have a fairly decent handle on how to switch between activities (based on this article: http://www.linux-mag.com/id/7498) but I'm not sure how to go about creating a new one (with eclipse).

  • 2 Once I have a new activity created, how can I set it as the default activity of my application? I presume I could just change the name of the classes...but is there a more elegant way to handle that (maybe within the AndroidManifest.xml)?

13 Answers 13

748

Yes, you use the AndroidManifest.xml file. You can actually even have more than one launcher activity specified in your application manifest. To make an activity seen on the launcher you add these attributes to your activity in the manifest:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
11
  • 57
    For anyone that doesn't know what the manifest this post is talking about, it is the AndroidManifest.xml in the root of your project. In Eclipse you can double click it and click the tab on the furthest right to edit the XML directly. Sep 3, 2010 at 8:29
  • 3
    great thanks. So by including that intent-filter node with it's child nodes, that makes whatever activity it's in the first one to load when the application starts?
    – Kyle
    Sep 3, 2010 at 14:55
  • 5
    @Kyle it will make that activity appear on the launcher page, you can have multiple activities with this intent-filter giving you multiple icons on the homescreen. May 18, 2011 at 18:00
  • 3
    you mention this line "ou can actually even have more than one launcher activity specified in your application manifest".Which activity will first launch if we have more than one activity Nov 29, 2011 at 5:06
  • 51
    This is correct answer, but I just noticed something odd: if you change the starting Activity to anything else, and the original launched activity still exists, the SDK won't be able to launch your application anymore. Somehow it has a reference to the activity on the launch configuration. So after you do the above change, you also need to go to "Run" > "Debug Configurations", find your project's build profile, tab "Android", and change the launched activity to either the default or the correct one under "Launch:". Not sure why the default was deselected for me, but changing it back worked.
    – zeh
    Feb 1, 2012 at 1:32
119

Go to AndroidManifest.xml in the root folder of your project and change the Activity name which you want to execute first.

Example:

<activity android:name=".put your started activity name here"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
1
  • 14
    if with this still doesn't work in Android Studio you have to click on the android icon(the one with the word app) and select "Edit configurations", then in the General tab, Activity section select "Launch default Activity"
    – Ed_
    Aug 25, 2014 at 17:23
58

If you are using Android Studio and you might have previously selected another Activity to launch.

Click on Run > Edit configuration and then make sure that Launch default Activity is selected.

Launch default Activity

3
  • if in AndroidManifest.xml there's no intent filter for launcher, this is the solution. Nov 6, 2015 at 14:45
  • 1
    This is applicable for Eclipse too. Just specifying the intent filters is not enough. The intent filters are used if the APK is executed directly by the user, but if the APK is executed by Eclipse, that installs it, tries to launch a specific activity. This specific activity is specified in "Project properties" (right click on the project) -> Run/Debug Settings. Jan 11, 2016 at 23:12
  • This is amazing! Thanks for the tip Apr 7, 2016 at 19:07
38
 <application
    android:icon="@drawable/YOUR_ICON"    <!-- THIS ICON(IMAGE) WILL BE SHOWN IN YOUR APPS -->
    android:label="MY APP NAME " >    <!-- HERE LABEL(APP NAME) -->
    <activity
        android:name=".application's starting activity"  <!-- (.)dot means current dir, if your activity is in another package then give full package name ex: com.xxx.Activity  -->
        android:label="LABEL FOR ACTIVITY "
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
0
23

Follow to below instructions:

1:) Open your AndroidManifest.xml file.

2:) Go to the activity code which you want to make your main activity like below.

such as i want to make SplashScreen as main activity

<activity
    android:name=".SplashScreen"
    android:screenOrientation="sensorPortrait"
    android:label="City Retails">
</activity>

3:) Now copy the below code in between activity tags same as:

<activity
    android:name=".SplashScreen"
    android:screenOrientation="sensorPortrait"
    android:label="City Retails">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

and also check that newly added lines are not attached with other activity tags.

18

This is easy to fix.

  • Changes to the Launcher activity are also stored in the Debug configuration.
  • Go to Run > Debug Configurations and edit the setting.
  • There is also a similar setting in Intellij under Run > Edit Configurations select Run default Activity and it will no longer save the setting in this fashion.
0
14

It's simple. Do this, in your Manifest file.

<activity
    android:name="Your app name"
    android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>
3
  • 1
    you should remove <category android:name="android.intent.category.HOME" />
    – Behrouz.M
    Oct 18, 2014 at 4:34
  • 2
    <category android:name="android.intent.category.DEFAULT" />, that is the very thing that do work here Aug 19, 2015 at 9:07
  • 1
    android.intent.category.HOME is for use in a Kiosk-mode style application, where the default launcher is replaced. Using this without replacing the Launcher will result in a prompt during the start of SystemUI asking which launcher to use. Also see: stackoverflow.com/questions/22911156/…
    – CJBS
    Oct 14, 2015 at 16:31
7
 <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
5

Just go to your AndroidManifest.xml file and add like below

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

then save and run your android project.

5

You add this you want to launch activity android:exported="true" in manifest file like

 <activity
      android:name=".activities.activity.MainActivity"
      android:windowSoftInputMode="adjustPan"
      android:exported="true"/>
  <activity

Open java file of this activity and right click then click on Run 'main Activity'

OR

Open java file of this activity and press Ctrl+Shift+F10.

1
  • What effect does this have? Just Launching? Nov 17, 2019 at 8:20
3

In a recent project I changed the default activity in AndroidManifest.xml with:

<activity android:name=".MyAppRuntimePermissions">
</activity>

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

In Android Studio 3.6; this seems to broken. I've used this technique in example applications, but when I use it in this real-world application it falls flat. The IDE once again reports:

Error running app: Default activity not found.

The IDE still showed a configuration error in the "run app" space in the toolbar (yellow arrow in this screenshot)

Error in "run app" configuration

To correct this error I've tried several rebuilds of the project, and finally File >> "Invalidate Cache/Restart". This did not help. To run the application I had to "Edit Configurations" and point at the specific activity instead of the default activity:

Edit configuration dialog box

2
  • Hide that path... It is really sensitive information there... Someone could copy your activity path and sell it on play store
    – PhysiOS
    Mar 24, 2021 at 5:12
  • @PhysiOS "sell your activity path on playStore" if I may ask, what do you mean by that Please. I have never heard of that... ever. Could you elaborate more please?? Oct 21, 2022 at 17:35
3

In AndroidManifest.xml

I changed here the first activity to be MainActivity4 instead of MainActivity:

Before:

    <activity android:name=".MainActivity" >
       <intent-filter>
           <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity2" />
    <activity android:name=".MainActivity3" />
    <activity android:name=".MainActivity4" />
    <activity android:name=".MainActivity5" />
    <activity android:name=".MainActivity6"/>

After:

    <activity android:name=".MainActivity" />
    <activity android:name=".MainActivity2" />
    <activity android:name=".MainActivity3" />
    <activity android:name=".MainActivity4" >
       <intent-filter>
           <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity5" />
    <activity android:name=".MainActivity6"/>
2

For anyone getting errors in their debug\AndroidManifest.xml file make sure that you include the tag! "<activity android:name=".MainActivity>"

For example:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.