1

I am having four activities named as first, second, third and fourth activity. I know that Manifest is very essential file and acts as a root of the application. What I need is, instead of displaying first activity (ie. Login Activity) it should display the third activity (ie. Instruction activity) at first when I run the whole application.

So, all these four activities are founded in Manifest file. So now, how does Manifest recognize which activity should be launched first and how does it give importance to third activity (Instruction activity) that is to be launched first instead of other activities?

Then, I also have to know the concept of when it comes to multiple activities may have multiple launchers so how does this Intent filter does a filter by specifying messages that an activity listens to? By the way, how does intent filter and launcher plays a role when it comes to multiple activities?

halfer
  • 19,824
  • 17
  • 99
  • 186
Achiever
  • 1,626
  • 10
  • 30
  • 54

4 Answers4

3

Each Activity, BroadcastReceiver, and Service in your AndroidManifest.xml has an Intent Filter that specifies how it interacts with the Android Environment. For example, BroadcastReceivers can specify what broadcast events it is listening to.

Activities can specify things like how they are seen in the home screen, or what files extensions can be opened in the app. Some apps don't have Activities or Intent Filters - and just use Services and BroadcastReceivers. If an app does use one or more Activities, the developer can optionally add the Intent Filter - but this is not required. If the user wants to provide a launcher for the user to be able to open the app, he or she must use this Intent Filter:

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

This will create a launcher with the application icon (or an activity icon if it is overridden with the android:icon attribute) and the name of the activity (specified by the android:label attribute). So for example, I could have a manifest like this:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_title" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".OtherActivity"
        android:label="@string/other_title"
        android:icon="@drawable/ic_other_launcher" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

This manifest states that there are two launcher Activities - MainActivity and OtherActivity. They have different icons and different names. They are also completely separate Activity - so each one will have to handle receiving new intent, just as you would any other Activity.

So, to answer your question - there isn't necessarily a main or first Activity, and there could be multiple main or first Activities.

Also keep in mind that first Activity may be configured changing an Activity's launch mode. By default each newly launched Activity would be a new instance of the same app - and would have separate back stacks rooted at the Activity that first opened via the Intent Filter.

Phil
  • 35,852
  • 23
  • 123
  • 164
0
In side Manifest File Mention these line     inside activity for launching this activity as launcher activity
 <activity
        android:name="com.example.themap.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
Swapnil
  • 654
  • 7
  • 27
0

Main activity contains these filters, depending on these filters main activity will launch at first time,

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

these filters should be declared only for one activity (i.e MainActivity). If you want to show any other activities at first you need to keep some conditions in MainActivity and call those activities according to that.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
  • 1
    It is not necessary for declaring only one activity as MAIN and LAUNCHER. With action as `android.intent.action.MAIN` it only says that this activity does not require any data to start and category `android.intent.category.LAUNCHER` says that it should be shown in the Launcher. – Manveer Chawla Feb 19 '14 at 03:51
  • @ManveerChawla : What do you mean "It is not necessary for declaring only one activity as MAIN and LAUNCHER"? – Achiever Feb 19 '14 at 03:59
  • Theoretically you can have as many activities as you want which declare intent filter with action MAIN and category LAUNCHER. It is just that applications dont have this usecase. – Manveer Chawla Feb 19 '14 at 05:53
  • @ManveerChawla if you declare Main and Launcher for every activity it create no of icons on home screen equals to no of activities you decrleared in manifest.. dont declare Main, Launcher to all the activities. – RajaReddy PolamReddy Feb 19 '14 at 06:04
  • Yes it does and that is the point. It all depends on application. My point is that it is not necessary to have only one activity do that, there is no restriction from platform. – Manveer Chawla Feb 19 '14 at 06:07
0

There is a intent-filter with the action item which says this

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

The is what makes it the default activity!

EDIT:

There can be multiple activities with the same intent filter, each of those activities would give a new icon with the icon associated with that activity. Clicking on the icon would open up to their respective activity first.

Aadi Droid
  • 1,689
  • 4
  • 22
  • 46
  • What does category mean and how does Intent filter works on here? – Achiever Feb 19 '14 at 03:52
  • an intent filter basically specifies the messages or broadcasts that an activity listens to! Category basically gives more information about what handles the intent! In this case 'LAUNCHER' specifies that this is the initial activity. – Aadi Droid Feb 19 '14 at 03:56
  • When your manifest is parsed, the activity with the MAIN action gets picked up as the first activity – Aadi Droid Feb 19 '14 at 03:59
  • 1
    @Meena you should also note that multiple `Activities` can have this intent filter - allowing your app to have multiple launchers. – Phil Feb 19 '14 at 04:08
  • @Phil : Yeah, when it comes to multiple activities that can have multiple launchers so how does this Intent filter does a filter by specifying messages that an activity listens to? Here, how does intent filter and launcher plays a role when it comes to multiple activities..Can you explain me clearly please? – Achiever Feb 19 '14 at 04:14
  • @Meena I added an answer to cover this fully: http://stackoverflow.com/a/21871216/763080 – Phil Feb 19 '14 at 04:42