无法识别启动活动:未找到默认活动

2024-04-20

我是android新手,遇到了一个问题。 控制台显示“无法识别启动活动:未找到默认活动”。 我已经添加了

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

在清单中。 我已经尝试过无效缓存/重新启动,仍然不起作用。 并且包含主要活动的类文件在 android studio 中变绿。我不知道这意味着什么。 这是我的清单文件。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mrrobot.mycoolweather" >
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <Activity       android:name="com.example.mrrobot.mycoolweather.activity.ChooseAreaActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </Activity>
</application>

</manifest>

The chooseAreaActivity is the one I want to use as launcher activity. enter image description here


For 主要活动在你的清单中你必须添加这个类别LAUNCHER(启动应用程序时的第一个活动):

<activity
    android:name=".MainActivity"
    android:label="YourAppName"
    android:theme="@style/AppTheme.NoActionBar" >
      <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

For 其他活动你必须将类别更改为DEFAULT:

<activity
    android:name=".OtherActivity"
    android:theme="@style/AppTheme.NoActionBar" >
    <intent-filter>
            <action android:name="package.OtherActivity" />

            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

检查这个Activity http://developer.android.com/guide/topics/manifest/activity-element.html和这个开始另一项活动 http://developer.android.com/training/basics/firstapp/starting-activity.html

所以你的代码是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mrrobot.mycoolweather" >
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".activity.ChooseAreaActivity"
        android:label="@string/app_name" >
          <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
    </activity>
</application>

</manifest>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法识别启动活动:未找到默认活动 的相关文章

随机推荐