android - 为什么当有 android:name ="android.intent.action.VIEW"时 Action android :name ="android.intent.action.MAIN" added into AndroidManifest. xml

标签 android android-studio

我知道我可以设置 <action android:name...>在 AndroidManifest.xml 中。

我认为 <action android:name...>只能赋值一次。

但是从下面的项目中,我发现<action android:name="android.intent.action.VIEW"/>当存在 <action android:name="android.intent.action.MAIN"/> 时添加到 AndroidManifest.xml ,为什么?

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>

最佳答案

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

来自 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.

换句话说,这是一个快捷方式,用于指示该应用处理一个 具有 MAIN 操作或 VIEW 操作的 Intent , 与 LAUNCHER 类别。

换句话说,这:

<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>

等同于:

<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>

文档还提供了an example .

关于android - 为什么当有 android:name ="android.intent.action.VIEW"时 Action android :name ="android.intent.action.MAIN" added into AndroidManifest. xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67632144/

相关文章:

android - 使用 SwipeRefreshLayout 时 Robo 脚本中止

java - 无法使用asyncTask.cancel()

android - 如何使用 Kotlin Coroutines 在 Retrofit 中处理 204 响应?

android - 如何修复这些 proguard 警告

android - 原生 Admob 广告导致窗口泄漏

Android Jar 库

java - 从单独的类添加到数组

android-studio - 在Mac上转到android studio的行快捷键键盘

android - 使用 gradle 从 Intellij IDEA 项目迁移到 Android-studio

android - 从Eclipse ADT迁移到Android Studio