0

i am new to android and my first question in this site so if made a mistake let me know. I am confused because some tutorials say

<intent-filter>

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

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

</intent-filter>

this is the start of the program.

The others say the program starts at onCreate() method when the user clicks the

app icon from the Home screen the onCreate() method is called. i think onCreate

method here act like listener to the start icon.

My question here

1) If onCreate called first what is the use of using MAIN and LAUNCHER ?`

2) If MAIN and LAUNCHER are the starting point who call the onCreate mehtod?

My question is not duplicate to this question my question is who is the starting point of android program if it is .MAIN the who is calling onCreate() method?

Community
  • 1
  • 1
Yirga
  • 881
  • 1
  • 12
  • 31
  • Possible duplicate of [What is the meaning of android.intent.action.MAIN?](http://stackoverflow.com/questions/25219551/what-is-the-meaning-of-android-intent-action-main) – OneCricketeer Mar 19 '16 at 19:51
  • It is not duplicate in this question it is saying what is .MAIN .LAUNCHER mean and my question is where does the android start executing .MAIN and or onCreate() method . – Yirga Mar 20 '16 at 06:27

1 Answers1

2

The intent-filter for

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

Means that activity is created as the "main method of your app". I believe you can only declare one of these.

The other intent-filter

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

Tells the launcher to display an icon in the app drawer, home screen, etc. with the name of the android:label attribute. You can have multiple of these in your manifest to go directly to other activities.


To answer your question, onCreate is not exactly the starting point for an Activity. Activities are run in order of the Android Lifecycle, so onCreate is not "called first". It is just the first opportunity you have to call setContentView() to inflate your layout.

As far as who or what starts the Activity, you, the user, click the app icon and the Launcher sends an android.intent.action.MAIN Intent to your application, which the Manifest will see and start the appropriate Activity.

Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245