You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

修改AndroidManifest后Android Studio无法识别默认启动Activity

解决Android Studio无法识别默认启动Activity的问题

我来帮你排查并解决这个问题,你的AndroidManifest.xml配置里有两个关键错误,导致Android Studio识别不了默认启动Activity:

1. Intent Filter 配置错误

你在SplashActivity<intent-filter>里把category标签写成了action标签,正确的启动Activity必须同时包含MAIN action和LAUNCHER category。

错误的代码片段:

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <action 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>

2. exported 属性设置错误

作为被系统Launcher启动的主Activity,android:exported必须设为true——因为外部应用(系统Launcher)需要访问并启动它。你当前设置的android:exported="false"会阻止系统访问这个Activity,自然无法被识别为默认启动项。

SplashActivityandroid:exported属性从false改为true即可。

修正后的完整SplashActivity配置

<activity 
    android:name=".main.SplashActivity" 
    android:configChanges="orientation|screenSize" 
    android:exported="true" 
    android:label="@string/app_name" 
    android:launchMode="singleTop" 
    android:theme="@style/DellTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

修改完成后,点击Android Studio顶部的File -> Sync Project with Gradle Files同步项目,就能看到Android Studio正确识别SplashActivity为默认启动Activity了。

内容的提问来源于stack exchange,提问作者Ajay Kulkarni

火山引擎 最新活动