6

I have created a Launcher app. Everything works fine but I get errors when booting up the device. If I turn my phone off and then I turn it back on I found out that the app gets started 2 times and both of them starts about the same time. Any help about this?

I have this in the manifest:

<application       
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.testing"

        android:launchMode="singleTask"
        android:clearTaskOnLaunch="true"
        android:stateNotNeeded="true"                 

        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" /> 
            <category android:name="android.intent.category.HOME"/> 
            <category android:name="android.intent.category.DEFAULT" />                 
        </intent-filter>
    </activity>
    .....

Of course, I do NOT use any android.intent.action.BOOT_COMPLETED

After booting the phone and after having the error, my app closes. Then, if I press the Home button then it starts normally (just one instance of it) and everything works ok.

Kara
  • 6,115
  • 16
  • 50
  • 57
Ton
  • 9,235
  • 15
  • 59
  • 103
  • Wait, so you are saying that when you restart your phone the application tries to start itself even though you don't have any receivers setup? – zgc7009 Apr 10 '14 at 20:08
  • Right! I guess because it is a Launcher. But I just want to it start once, not twice in a row. – Ton Apr 10 '14 at 20:10
  • So your HOME category intent-filter is causing launch on boot, but booting it twice? That is odd. Have a log? Is there a reasoning you have the DEFAULT category intent-filter as well? It has to be getting called as your default application somewhere. – zgc7009 Apr 10 '14 at 20:20
  • 1
    I read on the Net that I need to use Main, Home and Default to create a Launcher. Isn't it? – Ton Apr 10 '14 at 20:22
  • I guess you are right, I guess you are working with implicit intents. I don't know, just weird to have an application dual boot. – zgc7009 Apr 10 '14 at 20:25
  • Try setting the Launcher category filter as well? – zgc7009 Apr 10 '14 at 20:31
  • I did. Same thing... :-( – Ton Apr 10 '14 at 21:03
  • Looks like I am in the exact same scenario (launcher with its main activity set as singleTask launch mode). Did you find a solution? – GGirard Oct 05 '15 at 22:03
  • No I haven't. I don't remember exactly but I think I write a field in a database with the starting time. The second run checks that variable and if it is less than a few seconds it just finishes. This way only one run at the same time. – Ton Oct 05 '15 at 22:20
  • @Ton Did you find any solution ? – Rajeev Kumar May 17 '18 at 11:47
  • @Ton, did you find solution? Can you post it? – Akshatha S R Aug 07 '19 at 07:44

1 Answers1

1

I too had this issue. But got it fixed by changing the launch mode of the activity to singleTop.

In my case Splashscreen was the launcher. I set android:launchMode="singleTop" in manifest. But it didn't work.

After that I could see that the LoginActivity was the landing page means, the application waits for user input in that page. So I added android:launchMode="singleTop" to LoginActivity also. Now it is working.

Akshatha S R
  • 1,237
  • 1
  • 15
  • 30