Error running app: Default Activity not found解决办法

最近开始尝试从eclipse转移到Android Studio上来,总是遇到一些小bug,这里自己总结一下,以防以后给忘了


最新写了一个apk时,点击运行出现了Error running app: Default Activity not found的提示,明明是个简单的activity而已。

看这个提示,很明显是没有找到可以默认启动的activity

到AndroidManifest文件里看一下

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

    <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=".MainActivity">
        </activity>
    </application>

</manifest>


MainActivity是我自己之后新建的,连android.intent.action.MAIN都没有,这样怎么启动,加上了之后再启动,还是一样Error,看看自己以前写的app,再加上

<category android:name="android.intent.category.LAUNCHER" />

终于成功了,最终文件如下

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

    <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=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    </application>

</manifest>


总结一下:

android.intent.action.MAIN:用于决定应用程序最先启动的activity

android.intent.category.LAUNCHER:决定该Activity是否需要展示到launcher上
两者都需要写入主Activity才能正常启动


猜你喜欢

转载自blog.csdn.net/wangzici/article/details/78146727