遵循Android Studio入门指南时未发现默认活动错误

问题描述 投票:0回答:2

[在尝试针对Android Studio here的初学者教程时,我试图添加向上导航。但是,当我尝试运行它时,它给了我错误:

Error running 'app':
Default Activity not found

我的AndroidManifest.xml文件中的代码是:

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".DisplayMessageActivity"
        android:parentActivityName=".MainActivity">
        <!-- The meta-data tag is required if you support API level 15 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

</application>

</manifest>
android android-manifest intentfilter
2个回答
0
投票

这里可能发生了很多事情。首先,我建议您以敏锐的眼光检查所有对布局的命名引用以及后面的代码。有时通过编辑,您可以通过在名称中添加或删除字母来无意间更改和重命名文件。另外,有时使用IDE时,修改状态可能会过时,您有时可以清理/构建或重新启动IDE。待更新的IDE也可能是罪魁祸首。

作为最佳实践,您应该对代码进行版本控制。这将有助于减轻诸如此类的大多数问题。请查看以下有关此做法的Android建议的链接。

https://developer.android.com/studio/publish/versioning


0
投票

清单文件还应在<application> ... </application>中包含以下内容:

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

供参考:Intent Filters

© www.soinside.com 2019 - 2024. All rights reserved.