Why is action android:name="android.intent.action.VIEW" added into AndroidManifest.xml when there is a android:name="android.intent.action.MAIN"

Viewed 2756

I know I can set <action android:name...> in AndroidManifest.xml.

I think that <action android:name...> can only assigned one time.

But from the following project, I find <action android:name="android.intent.action.VIEW"/> is added into AndroidManifest.xml when there is a <action android:name="android.intent.action.MAIN"/>, why?

https://github.com/sanogueralorenzo/Android-Kotlin-Clean-Architecture

https://github.com/igorwojda/android-showcase

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sanogueralorenzo.namingishard">

    <application
        android:name=".App"
        ...
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:theme="@style/AppTheme.Splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />

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

</manifest>
2 Answers

But from the following project, I find is added into AndroidManifest.xml when there is a , why?

From the documentation that explains this.

You can create a filter that includes more than one instance of <action>, <data>, or <category>. If you do, you need to be certain that the component can handle any and all combinations of those filter elements.

In other words, this is a shortcut to indicate that the app handles an intent that either has the MAIN action or the VIEW action, with the LAUNCHER category.

In other other words, this:

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

Is equivalent to this:

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

The documentation also provides an example.

To enable Google to crawl your app content and allow users to enter your app from search results, you must add intent filters for the relevant activities in your app manifest. These intent filters allow deep linking to the content in any of your activities. For example, the user might click on a deep link to view a page within a shopping app that describes a product offering that the user is searching for.

this is the first reason and the second one is

ACTION_VIEW Use this action in an intent with startActivity() when you have some information that an activity can show to the user, such as a photo to view in a gallery app, or an address to view in a map app.

while The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data. so activity can have both

Related