简体   繁体   中英

Could not identify launch Activity: Default Activity not found

I'm new to android and I have encounterded a problem. The console said that "Could not identify launch activity: Default Activity not found". I have add

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

in manifests. And I have tried Invalidate caches/Restart,still not worked. And the class file which contains the main activity turn green in android studio. I don't know what that means. This is my manifests file.

<?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. 在此处输入图像描述

For main activity in your manifest you have to add this with category LAUNCHER (First Activity on launch app):

<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 other activity you have to change category to 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>

Check this Activity and this Start Another Activity

So your code is:

<?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>

Sometimes it is solved just restarting Android Studio

单击“文件”,然后单击“使缓存无效”


I had the "Default Activity not found" problem a couple of times and I could solved restarting my android Studio.

Although the question is kind of outdated, I would add the following to all the given answers:

For multi-module projects check carefully that you modify the Manifest corresponding to the Configuration you are trying to run.

Had the same problem and spent 20 minutes just to discover that I was trying to run wrong configuration (with an Application in ModulbeB , while thinking that I was running one from ModuleA ).

And sometimes you are working on other module default runnable module changes so you have to change it. 在此处输入图像描述

如果您在升级 IDEA、升级 Android Studio 版本或生成新 APK 后发现该错误,您可能需要刷新 IDE 的缓存。

File -> Invalidate Caches / Restart...

In your manifest file there was wrong element name (Activity change to activity) declared

<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>

Change it to:

 <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>

i had these issues with my project:

  • Default activity not found

  • xml intellisense was not working

  • kotlin standard functions were not detecting

All my above issues were resolved by Deleting System cache of Android Studio 3.3 at the home path, and it's working nicely for me,, Steps:

  1. exit Android Studio

  2. Go to path > C:\Users\YOUR_WINDOW_USER_NAME.AndroidStudio3.3\system

  3. Then you have a \caches folder, delete this caches folder

  4. Now open Android Studio and load your project

Worked for me.. i wasted couple of hours resolving this issue and finally it got resolved in this way.

Exit your android studio IDE. Then locate the "caches" folder in .AndroidStudio3.2 folder.

Location

C:\Users\YOUR_USERNAME\.AndroidStudio3.2\system\caches

For example.

Let's assume say YOUR_USERNAME is called Admin.

C:\Users\Admin\.AndroidStudio3.2\system\caches

Delete the caches folder and start your android studio IDE.

I have tried solutions here and other questions

  • clean & rebuild & invalidate and restart
  • make sure that activity has LAUNCHER as category
  • delete Android cache folder

at End, activity tag was has <activity android:name="com.exmaple.todo.MainActivity" /> when i changed it to <activity android:name=".MainActivity" /> app worked.

I hope it help you if other solution not work.

If your activity is in a different module (eg ':library) und you forgot to specify the subproject in the dependencies{} scriptblock of your :app module, the manifest of :library and therefore the activities it declares, are not imported.

dependencies {
   api project (':library')

You may check whether all activities show up in your app-debug.apk by using the following Android Studio menu command:

->Build->Analyze APK->app-debug.apk

Now open the AndroidManifest.xml and check its activity declarations.

When I upgraded Android Studio to 2021.1.1.23 somehow my Run Configuration was switched from app to models , producing this error. Switching back to app resolved the issue for me.

My main activity was not declared in Android Manifest File. That's the reason which came that error. This error come because of a declaration problem of Android Manifest file. Please check it. :D

This happened to me aswell took me ages to figure out why, but a weird bug I spotted is that if you run the app with breakpoints in your code without debugging mode it will cause this error to happen.

Quick fix for now: Only use breakpoints for degbugging mode.

Check your duplicate initialize activity in your AndroidManifest.xml

Like bellow:

        <activity android:name=".nim.qiaqia.lota.LotaProduct"/>
        <activity android:name=".nim.qiaqia.lota.LotaOrderDetail"/>
        <activity android:name=".nim.qiaqia.main.activity.RechargeListLotaActivity"/>
        <activity android:name=".nim.qiaqia.lota.MiningCoinLota"/>
        <activity android:name=".nim.qiaqia.lota.LotaOrderDetail"/>

that can causes ""Default Activity not found" also. So, remove it and see. its works! :)

In my case android manifest was correct . I tried to invalidate Caches and restart but not worked. Then Rebuild project and it also did not work.

Then I realized that last night I added a new library to build Gradle, it was this: implementation 'com.yalantis:eqwaves:1.0.1' And after removing this everything worked fine.

TIP: "Always have a track of things you do in your project, otherwise you will end up wasting your time"

If you only enabled building the app via app bundle, then this error might also occure when you try installing it as a default APK. Change the deployment option to APK from App Bundle and you are good to go.

I got this error in android 12+ after changing launch activity adding intent-filter but not make it exported.
so not forget.

           
android:exported="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM