46

I want to create own activity as main activity rather than using default MainActivity.

How can I define that in android manifest?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sathish
  • 1,147
  • 3
  • 10
  • 20

5 Answers5

72

In your manifest file , use the below code to declare an activity as a launcher activity:

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

From Android Developer docs:

ACTION_MAIN activity: Start up as the initial activity of a task, with no data input and no returned output.

CATEGORY_LAUNCHER: The activity can be the initial activity of a task and is listed in the top-level application launcher`.

Community
  • 1
  • 1
Nargis
  • 4,687
  • 1
  • 28
  • 45
16

In AndroidManifest.xml file inside application tag add an activity tag and remove action MAIN from old activity tag set that as default

 <application...... >
    <activity
        android:name=".DefaultActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".NewActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

 </application>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
prabhat
  • 273
  • 1
  • 7
  • what are the uses of main and default; and explain me the differences of both – Sathish Mar 15 '12 at 13:52
  • 1
    The "main" activity is the activity that loads first and the rest of your application. Every application can have multiple activities, therefore you can list other activities to load and use later on but you can only have one "main" activity. – Jared Burrows Mar 31 '12 at 02:44
6

You can use in manifest file:

<activity
    android:name=".DefaultActivity"
    android:label="@string/app_name" 
      android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name=".NewActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity> 

It is very important:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
devio
  • 607
  • 9
  • 29
tugbacevizci
  • 81
  • 1
  • 7
3

It's Simple. In your android manifest file add,

<activity
    android:name="Your Activity 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>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
1

In Xamarin, you can add MainLauncher = true above class definition like this:

[Activity(Label = "UserActivity", MainLauncher = true)]
public class UserActivity : ListActivity
Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
ManuQiao
  • 708
  • 8
  • 20