3
  1. If the intent filters are to resolve implicit intents, then why does the MainActivity(which is the very first activity that is run when app is launched) has an intent filter?
  2. Who send an implicit intent to it?
  3. What if the sent implicit intent doesn't have proper data ?
sofs1
  • 3,834
  • 11
  • 51
  • 89

2 Answers2

2

Well, how does the system know which activity is the main activity? It isn't the name- the system doesn't care about the name. Its the activity with the intent filter that says its the main activity.

It can also have other intent filters to launch it any other way you may want. For example, you may have an intent filter to launch it via a deep link.

As for proper data- if launched from the app list or homescreen, it won't have any data. Its on the programmer of the app to make sure that it can do something that makes sense in that case.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • 1) Got it. 2) Got it, Says for example if a user clicks an address in a website, our maps app can get started by using the intent filter. Is my understanding correct? May I know what is meant by deep link? – sofs1 Jan 07 '17 at 04:02
  • A deep link for mobile is when a url like http://example.com/myUrl opens up an Activity in an app instead of a webpage. – Gabe Sechan Jan 07 '17 at 04:03
  • default intent filter won't handle deeplinks. for that you need to create a seperate intent filter. – Damanpreet Singh Jan 07 '17 at 04:14
  • @DamanpreetSingh I didn't say it would. I said that's another reason the main activity could have a filter. – Gabe Sechan Jan 07 '17 at 04:54
1
  1. It has CATEGORY_LAUNCHER and ACTION_MAIN . android.intent.action.MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created. CATEGORY_LAUNCHER tells that your activity should be displayed in the top-level launcher.

https://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN

  1. Launcher sends implicit intent to it. This is how launcher knows which activity is to be opened on click.

  2. If you send improper data it will not open your activity. For ex: If you try to start your main activity using implicit intent only in startActivity then it will not start because there is CATEGORY_DEFAULT associated with it. You need to add one more intent_filter to your activity to resolve the intents.