我知道我可以设置 <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/