7

Android is launching wrong activity when I start app.

Manifest.xml :

<activity
    android:name="com.company.app.activities.RS_SplashScreenActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name="com.company.app.activities.RS_PreviousLauncherActivity"
    android:label="@string/app_name"
    android:theme="@style/myTheme" >
</activity> 

I added a new Activity RS_SplashScreenActivity and set it as launcher activity. Still it tries to launch RS_PreviousLauncherActivity which used to be a launcher activity before adding RS_SplashScreenActivity.

I am sure that android chooses wrong launcher activity on account of below logs from console.

Console :

[2013-10-10 12:03:58 - app] Android Launch!
[2013-10-10 12:03:58 - app] adb is running normally.
[2013-10-10 12:03:58 - app] Performing com.company.app.activities.RS_PreviousLauncherActivity activity launch
[2013-10-10 12:04:01 - app] Uploading app.apk onto device '5C78E6332221CD6A1'
[2013-10-10 12:04:05 - app] Installing app.apk...
[2013-10-10 12:04:12 - app] Success!
[2013-10-10 12:04:12 - app] Starting activity com.company.app.activities.RS_PreviousLauncherActivity on device 5C78E6332221CD6A1
[2013-10-10 12:04:12 - app] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.company.app/.activities.RS_PreviousLauncherActivity }
[2013-10-10 12:04:13 - app] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.company.app/.activities.RS_PreviousLauncherActivity } from null (pid=4530, uid=2000) not exported from uid 10084
[2013-10-10 12:04:13 - app] ActivityManager: at android.os.Parcel.readException(Parcel.java:1425)
[2013-10-10 12:04:13 - app] ActivityManager: at android.os.Parcel.readException(Parcel.java:1379)
[2013-10-10 12:04:13 - app] ActivityManager: at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1783)
[2013-10-10 12:04:13 - app] ActivityManager: at com.android.commands.am.Am.runStart(Am.java:463)
[2013-10-10 12:04:13 - app] ActivityManager: at com.android.commands.am.Am.run(Am.java:108)
[2013-10-10 12:04:13 - app] ActivityManager: at com.android.commands.am.Am.main(Am.java:81)
[2013-10-10 12:04:13 - app] ActivityManager: at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
[2013-10-10 12:04:13 - app] ActivityManager: at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
[2013-10-10 12:04:13 - app] ActivityManager: at dalvik.system.NativeStart.main(Native Method)

Any idea why this happens?

Edit :

public class RS_SplashScreenActivity extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(RS_SplashScreenActivity.this, RS_PreviousLauncherActivity.class);
                RS_SplashScreenActivity.this.startActivity(i);

                // close this activity
                RS_SplashScreenActivity.this.finish();
            }
        }, SPLASH_TIME_OUT);
    }

Edit : When I remove activity tag for RS_PreviousLauncherActivity, it detects correct activity as launcher but when I add activity tag again then it starts selecting wrong activity.

Edit : I get below logs in console. May be this has something to do with my problem.

[2013-10-09 10:27:04 - app] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.james.mime4j.message.Header$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

And one more thing, this same project works on other machine.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Geek
  • 8,280
  • 17
  • 73
  • 137

7 Answers7

24

Right click your project and select "Run As" > "Run Configurations...". Check in the dialog that pops up whether you have "Launch Default Activity" selected in the Android tab:

Run Configurations Dialog

It is likely that on the machine that keeps launching the old activity, it was set to launch that specific activity (the second radio button) by accident.

Joe
  • 14,039
  • 2
  • 39
  • 49
  • 1
    Wow, thank you! So simple and this had me scratching my head for an hour. The odd thing is that I never modified the start activity to begin with. It just happened on its own somehow. Android Studio bug/glitch? – AlexVPerl Feb 02 '15 at 20:43
  • This worked of course, it's obvious, no idea why didn't try there. But still no idea why it was added there in the first place, why would it – Odaym Feb 14 '15 at 13:00
  • 1
    This is **Run -> Edit Configurations -> Launch Options -> Default Activity** in Android Studio – zgc7009 Aug 09 '16 at 21:49
  • I guess I accidentally set this somehow... This problem was driving me crazy! Thank you!! – Sakiboy Aug 11 '16 at 20:31
  • This was set to the wrong activity on my project too. Does android studio set this by default by any chance? – Aci89 Jul 17 '17 at 03:05
0

Uninstall app, and install it again, sometimes appLauncher in your launcher holds old reference, i had similar problem with icon, I changed app icon, but it showed as old one.

Drake29a
  • 896
  • 8
  • 23
0

Clean the project from Eclipse.

  1. Menu->Project->Clean->Select you project-> ok

It will clean the project and generate the binary again. after that install the application and check.

Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47
0

Try this:

<application
      ..... 
     android:theme="@style/myTheme" 
>

<activity
    android:name="com.company.app.activities.RS_SplashScreenActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name="com.company.app.activities.RS_PreviousLauncherActivity"
    >
</activity> 
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
0

Perhaps you might want to do a splash screen in the traditional way...That way you know it will work, see link: How to make a Splash screen

Community
  • 1
  • 1
Ndupza
  • 780
  • 1
  • 6
  • 16
0

Clean your project or uninstall your application. Still it didn't work then delete "gen" folder and then clean your project and run.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
-2

Check the code of your RS_SplashScreenActivity. check all the time interval and redirection to RS_PreviousLauncherActivity.

If it doesn't solve your problem the do onething

1: Right click on project from eclipse

2: click on Source

3: Then click on Cleanup..

4: Click on Finish

5: Atlast after uninstall the app from your device reinstall it.

It will might fix your problem.

Edited

Try this:

<application
      ..... 
     android:theme="@style/myTheme" 
>

<activity
    android:name="com.company.app.activities.RS_SplashScreenActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
        android:name="com.company.app.activities.RS_PreviousLauncherActivity"     
       >
        <intent-filter>
            <action android:name="com.company.app.activities.RS_PreviousLauncherActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
Avijit
  • 3,834
  • 4
  • 33
  • 45
  • Tried. Still tries to launch `RS_PreviousLauncherActivity `. The problem is not in `RS_SplashScreenActivity` because on console logs it prints the name of activity it tries to launch and that is `RS_PreviousLauncherActivity `. – Geek Oct 08 '13 at 11:15
  • Do one thing for testing try one thing remove RS_PreviousLauncherActivity from manifest . and try to launch RS_SplashScreenActivity and let me know it is coming or not. @Akash – Avijit Oct 08 '13 at 11:19
  • The problem in may be splash screen may be. If you will post it i can assist you further..@Akash – Avijit Oct 08 '13 at 11:48
  • Look at edited question. I added code for RS_SplashScreenActivity. – Geek Oct 08 '13 at 11:56
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/38784/discussion-between-akash-and-andru) – Geek Oct 08 '13 at 12:02