- 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?
- Who send an implicit intent to it?
- What if the sent implicit intent doesn't have proper data ?
Why does the Main activity has an intent filter?
786 views Asked by sofs1 At
2
There are 2 answers
4
On
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.
https://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN
Launcher sends implicit intent to it. This is how launcher knows which activity is to be opened on click.
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.