如何解决Android Studio中“无法确定Activity名称”的错误?
解决“Unable to determine activity name”错误及配置启动页
问题根源
你的Manifest文件里没有指定应用的启动Activity,系统无法识别打开App时该启动哪个页面;同时Android 12(API 31)及以上版本要求,作为启动入口的Activity必须显式设置android:exported="true",否则会触发异常。
修复步骤
1. 配置SplashScreen为启动入口
修改SplashScreen的Activity配置,添加android:exported="true"和启动专用的intent-filter,让系统识别它为App的启动页:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SmartHub" tools:targetApi="31"> <!-- 配置为启动入口的SplashScreen --> <activity android:name=".SplashScreen" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FormCadastro" android:exported="false" /> <activity android:name=".FormLogin" android:exported="false" /> <activity android:name=".Inicio" android:exported="false" android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar" /> </application> </manifest>
2. 实现SplashScreen跳转到FormLogin的逻辑
在SplashScreen的代码中添加延迟跳转逻辑(示例延迟2秒):
Kotlin示例:
class SplashScreen : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash_screen) // 延迟跳转至FormLogin Handler(Looper.getMainLooper()).postDelayed({ startActivity(Intent(this, FormLogin::class.java)) finish() // 关闭SplashScreen,避免返回键回到此页面 }, 2000) // 2000毫秒=2秒 } }
Java示例:
public class SplashScreen extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen); // 延迟跳转至FormLogin new Handler(Looper.getMainLooper()).postDelayed(() -> { startActivity(new Intent(SplashScreen.this, FormLogin.class)); finish(); // 关闭SplashScreen,避免返回键回到此页面 }, 2000); // 2000毫秒=2秒 } }
3. 验证配置
点击Android Studio顶部的Sync Project with Gradle Files按钮同步项目,然后运行App。此时系统会先启动SplashScreen,延迟后自动跳转到FormLogin,“Unable to determine activity name”错误也会消失。
内容的提问来源于stack exchange,提问作者Ranyê Wilames
相关产品推荐
相关产品推荐

