user264953
user264953

Reputation: 1967

Error while launching activity through intent

I am trying to launch an activity with the following code:

Intent i = new Intent();
i.setClassName("com.android.launcher2", "com.android.launcher2.Launcher");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

I get the following exception with this code above:

01-01 00:05:03.617: ERROR/AndroidRuntime(1458): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.LOCALE_CHANGED flg=0x30 } in com.android.launcher2.LauncherModel@4194bcc0
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at   android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.os.Handler.handleCallback(Handler.java:605)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.os.Looper.loop(Looper.java:137)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.app.ActivityThread.main(ActivityThread.java:4368)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at java.lang.reflect.Method.invokeNative(Native Method)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at java.lang.reflect.Method.invoke(Method.java:511)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at dalvik.system.NativeStart.main(Native Method)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.launcher2/com.android.launcher2.Launcher}; have you declared this activity in your AndroidManifest.xml?
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.app.ContextImpl.startActivity(ContextImpl.java:889)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at com.android.launcher2.LauncherModel.onReceive(LauncherModel.java:634)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458):     ... 9 more

I am trying to start the activity from a class in the same package - com.android.launcher2 , and I have this activity (Launcher) defined in manifest.

Can someone please let me know what causes this error, though everything looks OK

EDIT

Intent i = new Intent(getApplicationContext(), com.android.launcher2.Launcher.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

I have done exactly this and tested. Now, the activity is resumed in the following sequence - onNewIntent() , onResume(). Instead I need onDestroy() and onCreate() sequence to happen. How can I accomplish this? Any help from anyone in this regard is much appreciated

Upvotes: 1

Views: 17120

Answers (8)

Nikhil Lotke
Nikhil Lotke

Reputation: 665

My case:

Android Manifest Before:

<activity android:name=".modules.login.LoginActivity" />

Android Manifest After:

<activity android:name="com.domain.sample.modules.login.LoginActivity" />

Above change helped to redirect to the reference at runtime and resolved this issue.

Upvotes: 0

Braian Coronel
Braian Coronel

Reputation: 22905

This could happen if your device manages multiple accounts and the application is already installed in an account other than your current session.

You would have to uninstall the app on all accounts and reinstall it in your current account session.

Upvotes: 1

Fabian Knapp
Fabian Knapp

Reputation: 1382

Addition to your edit: take a look at your intent flag i think there is the problem look at the android dev they explicit say that this flag is often combined with a multiple flag.

Upvotes: 0

AndroDev
AndroDev

Reputation: 3304

Follow this:


In Java

    Intent i = new Intent();
    i.setClassName("com.android.launcher2", "com.android.launcher2.Launcher");
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);

In manifest

        <activity android:name="com.android.launcher2.Launcher" class="com.android.launcher2.Launcher">
        </activity>

Upvotes: 3

Hulk
Hulk

Reputation: 2561

Class not found exception means...either you have not defined the class in your manifest file or you are making the class explicitly..so check you manifest file.

And do it in your activity--

   Intent intent = new Intent(act1.this, act2.class);
   startActivity(intent);

Upvotes: 1

AndroDev
AndroDev

Reputation: 3304

try this:

        Intent i = new Intent(getApplicationContext(), com.android.launcher2.Launcher.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);

Upvotes: 1

Tschegewara
Tschegewara

Reputation: 169

try to add .class to your class name.

Upvotes: 1

Fabian Knapp
Fabian Knapp

Reputation: 1382

Did you unregister all broadcast Receivers in LauncherModel in onStop() ?

Upvotes: 1

Related Questions