user3273595
user3273595

Reputation: 83

Android: ActivityNotFoundException Unable to find explicit activity class

Got ActivityNotFoundException when trying to start activity

java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.mypackagename/com.mypackagename.StartActivity}:
    android.content.ActivityNotFoundException: Unable to find explicit activity class
    {com.mypackagename/com.mypackagename.MainActivity}; 
    have you declared this activity in your AndroidManifest.xml?
    ....

I'm using this code to start new activity

Intent MainActivity = new Intent (this, MainActivity.class);
MainActivity.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
startActivity(MainActivity);
finish();

But I got a crash report from Google developer console for ActivityNotFoundException (like above message) from 1 user

I have declared both activity inside my manifest

....
<activity 
    android:name="com.mypackagename.StartActivity"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:theme="@style/AppTheme"
    android:noHistory="true" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name="com.mypackagename.MainActivity"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:theme="@style/AppTheme"
    android:configChanges="orientation|keyboardHidden|screenSize" >
</activity>

Everything works fine as I test on several Nexus device and each API version using Emulator.

StartActivity class extends Activity, and MainActivity class extends ActionBarActivity

Is there any problem with my code when starting new activity or something else?

Should I surround it with?

try {
    ...
} catch (Exception ...) {
    ...
}

Upvotes: 0

Views: 1352

Answers (1)

Simas
Simas

Reputation: 44118

Try renaming the Intent variable as you are using the same name as the class name.

Instead try

Intent intent = new Intent (this, MainActivity.class);;

Upvotes: 1

Related Questions