yzycqu
yzycqu

Reputation: 35

How the android app's first activity launched?

when we created a helloworld application using ADT, The "MainActivity" will be loaded, Because every program has a entry, such as the "main" function, For android apps, We can declare many activities in the file called "AndroidManifest.xml", So I wanna know how this activity launched by android framework? which is android apps "main" entry ?

Upvotes: 0

Views: 615

Answers (4)

Vinith
Vinith

Reputation: 1274

Only one activity should have the "main" action and "launcher" category...

So in the AndroidManifest.xml file, you should essentially have only one:

action android:name="android.intent.action.MAIN"

category android:name="android.intent.category.DEFAULT"

Activities will very often need to support the CATEGORY_DEFAULT so that they can be found by Context.startActivity(). So, CATEGORY_DEFAULT can appear number of times.

Android does not grab whichever one appears first in the manifest but it starts with activity having CATEGORY_LAUNCHER.

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

Upvotes: 0

Ketan Ahir
Ketan Ahir

Reputation: 6738

the activity declared with intent filter

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

will be launched first.

<activity
        android:name="com.example.hello.HelloActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Upvotes: 0

Vikram Singh
Vikram Singh

Reputation: 1420

Manifest tells android which activity to launch. Actually, when you click app icon, OS consults with application's manifest file and looks for the launcher activity. You can declare any activity as your launcher by writing this inside your activity tag in manifest.

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

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

Manifest always acts as interface between your application and OS. It provides all the information about your app to OS like what are the permissions, what activities, what receivers you are using in your app including your LAUNCHER ACTIVITY.

Upvotes: 2

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

because of this

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

Upvotes: 0

Related Questions