62

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. enter image description here

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
Jiawei Yang
  • 1,553
  • 2
  • 12
  • 17

17 Answers17

106

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>
Michele Lacorte
  • 5,323
  • 7
  • 32
  • 54
21

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. enter image description here

behrad
  • 1,228
  • 14
  • 21
frumle
  • 593
  • 5
  • 15
14

Sometimes it is solved just restarting Android Studio

Click on "File" and then "Invalidate Cache"


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

Orlando Herrera
  • 3,481
  • 1
  • 34
  • 44
6

If you see that error occur after upgrading your IDEA, upgrading Android Studio version, or Generating a new APK, you may need to refresh the IDE's cache.

File -> Invalidate Caches / Restart...
Mahendran Candy
  • 1,114
  • 17
  • 17
5

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>
Rohit Kumar
  • 728
  • 9
  • 13
2

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.

rwst
  • 2,515
  • 2
  • 30
  • 36
  • I had the same problem when trying to download, build and run the ExoPlay Uamp demo program. Selecting 'app' instead of the default 'automotive' fixed that too. – steven smith Apr 09 '22 at 02:10
2

It is likely that the action is not in the manifest. This is the fix

Attached is an image manifest

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 26 '22 at 09:54
1

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.

Shoaib Mushtaq
  • 595
  • 4
  • 17
1

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.

Nelson Katale
  • 1,309
  • 15
  • 21
Navin Kumar
  • 3,393
  • 3
  • 21
  • 46
1

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.

Mahmoud Mabrok
  • 1,362
  • 16
  • 24
1

If your activity is in a different module (e.g. ':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.

roplacebo
  • 2,837
  • 2
  • 17
  • 19
1

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"

nima moradi
  • 2,300
  • 21
  • 34
0

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

chamiya
  • 25
  • 9
0

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.

dave o grady
  • 788
  • 8
  • 12
0

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! :)

Izzamed
  • 83
  • 4
0

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"

Vijay
  • 1,163
  • 8
  • 22
0

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.

bd1909
  • 155
  • 1
  • 6