0

Android Studio is acting weird today. I was developing an application and until today it was running fine but now, first it crashed my HTC Drivers and adb stopped working.

I managed to fix it but now whenever I run my application it keeps on giving me Error Running App: Default Activity not found.

It is becoming annoying. I have already google it but most of the answers referring to File > Invalidate Caches & Restart... > Invalidate & Restart. I tried this solution. But again on running the app right after Installing APKs..., Android studio again throwsDefault Activity Not Found.

Here is my Manifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/base_logo"
    android:label="@string/app_name"
    android:roundIcon="@drawable/base_logo"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <service
        android:name=".application.classes.map_manager.FetchAddressIntentService"
        android:exported="false" />

    <activity android:name=".application.activities.MainActivity" />
    <activity android:name=".authentication.activities.NumberActivity"/>
    <activity android:name=".authentication.activities.PasswordActivity" />
    <activity android:name=".authentication.activities.NameActivity" />
    <activity android:name=".authentication.activities.VerificationActivity" />
    <activity android:name=".authentication.activities.LoginActivity" />
    <activity android:name=".application.activities.MapActivity" />
    <activity android:name=".application.activities.SplashActivity" android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.MAIN" />

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

I have already provided the Sources directory in build.gradle. Sometimes it just works fine. Most of the time after restarting PC, it runs for the first time completely fine. But for the next run, it keeps giving "Default activity not found"

Default Activity: SplashActivity.kt

package com.kingstechnology.user.buraq_rider.application.activities

import android.content.DialogInterface
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.support.v7.app.AlertDialog
import android.util.Log
import android.widget.Toast
import com.kingstechnology.user.buraq_rider.R
import com.kingstechnology.user.buraq_rider.application.classes.AppConfiguration
import com.kingstechnology.user.buraq_rider.authentication.activities.NumberActivity

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
    }

    override fun onResume() {
        super.onResume()
        checkInternetConnectivity()
    }

    /**
     * This method will check for internet connectivity,
     * On Success: This method will redirect to UserManager page if user is not Logged In
     * On Failure: This method will ask to turn on wifi and repeat the proccess
     */
    private fun checkInternetConnectivity(){
        if (AppConfiguration.isInternetConnected(this)) {

            // If user is logged in take it to Map Activity
            if (AppConfiguration.isUserLoggedIn(this)) {
                // Go To Map Activity
            }
            // If user is not logged in
            else {
                val intentForNumberActivity =
                        Intent(this@SplashActivity, NumberActivity::class.java)
                startActivity(intentForNumberActivity)
                finish()
            }

        } else {

            // Ask user to connect to internet
            AppConfiguration.askForInternet(this)
        }
     }
   }
thezeeshantariq
  • 308
  • 2
  • 16
  • Possible duplicate of [Error: Default Activity Not Found](https://stackoverflow.com/questions/15825081/error-default-activity-not-found) – André Sousa Nov 02 '18 at 18:52
  • I have already checked this answer. But in my case, Android Studio allows me to run the application on my "HTC M8 One" for the first time. But for the rest, it keeps giving me that error. Also it make "adb" stops working.. – thezeeshantariq Nov 02 '18 at 18:54

2 Answers2

1

I have sorted out the answer myself. The problem was that whenever I run my application (even a new project) it runs for the first time like a piece of cake, but from next run onward, it keeps on giving Default activity not found.

Solution It happens, that the cause of this error was not the code but the settings of Android Studio. As I had re-installed the android studio with no fruit. So here this is what I did.

  1. Open User folder that was in my case:

    C:\Users\<UserName>\

  2. Delete Folder named as:

    .AndroidStudio<version>

  3. Restart Android Studio

thezeeshantariq
  • 308
  • 2
  • 16
0

Try this code

<activity android:name=".application.activities.SplashActivity" 
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
ShehrozEK
  • 180
  • 1
  • 1
  • 6