1

Is a custom Android launcher supposed to signal somehow that it is ready?

I don't get BOOT_COMPLETED with my launcher, but when I use the system's original launcher BOOT_COMPLETED gets sent. Am I supposed to do something special in the launcher code to signal that it is ready?

Why is BOOT_COMPLETED not sent when I do my own launcher compared to the system's own launcher? My launcher works well, except BOOT_COMPLETED is never broadcasted when I use it.

UPDATE
It seems the launcher Activity has to be visible (and touchable?) at least until BOOT_COMPLETED has been sent, otherwise BOOT_COMPLETED doesn't seem to be sent at all. Can anyone confirm this?

I use black Activity with this and it doesn't work:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

UPDATE I get this in logs, to show you that BOOT_COMPLETED really isn't sent:

01-04 17:33:39.384 541-599/system_process W/AudioService: onLoadSoundEffects() called before boot complete

After 20 minutes it's still the case. I am on KitKat 4.4.4.

UPDATE

Launcher manifest:

<activity android:name=".application.HomeInterceptorActivity"
          android:label="@string/app_name"
          android:launchMode="singleTop"
          android:clearTaskOnLaunch="true"
          android:stateNotNeeded="true"
          android:theme="@style/Invisible"
          android:excludeFromRecents="true"
          android:exported="false"
          android:noHistory="true">
          <!--android:taskAffinity="">-->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <!--<category android:name="android.intent.category.LAUNCHER"/>-->
    </intent-filter>
</activity>

UPDATE It seems that the problem occurs if another Activity is started directly in the launcher's onResume() before BOOT_COMPLETED has been sent (Though it might equally well be a coincidence caused by some race-condition). It feels like the launcher has to spend some time in its own activity to allow BOOT_COMPLETED to be sent.

JohnyTex
  • 3,323
  • 5
  • 29
  • 52
  • _"Is a custom Android launcher supposed to signal somehow that it is ready?"_ No, a launcher is just an app, the system is the one that signals about boot completeness to all apps involved, including launchers. But don't be confused, when `BOOT_COMPLETED ` is being broadcasted by the system the launcher is already running... _"Why is BOOT_COMPLETED not sent"_. I assume there is a mistake either with registering the `BroadcastReceiver` or receiving the `Action`. You should post the relevant code. – Onik Jan 04 '17 at 16:25
  • OK. The thing is BOOT_COMPLETED is not sent even in syslogs. Sound doesn't even work because it is not initialized until BOOT_COMPLETED. I know my receivers are correct because they work when BOOT_COMPLETED is actually sent. – JohnyTex Jan 04 '17 at 16:34
  • What I mean is that my launcher shows up when device is restarted (shows up not on BOOT_COMPLETED but before). It also shows my activity when I press home. The sound driver seems to start on BOOT_COMPLETED, but since it is never sent, no sound can be heard, for instance when I click buttons. – JohnyTex Jan 04 '17 at 17:00
  • I believe so, yes. The problem seems to appear as I investigate here, when I start another activity in onResume() directly in my launcher activity. Any thoughts on that? – JohnyTex Jan 04 '17 at 17:38
  • 1
    _"I believe so, yes"_?? Are you making a custom ROM or just a launcher app for a stock `Android`?..._"when I start another activity in onResume() directly in my launcher activity"_ My best guess is that by the time the launcher's `onResume()` returns `HomeInterceptorActivity` isn't the top `Activity` in back stack due to starting a new `Activity`. Do you have a specification to do so? – Onik Jan 04 '17 at 19:57
  • It is stock rom as far as I know. It is a Pipo X8 device and I don't think they have made any customizations to the rom. I am not writing custom rom. – JohnyTex Jan 10 '17 at 12:34
  • 1
    Why is it important that HomeInterceptorActivity is the top activity for BOOT_COMPLETED to be sent? Is it not strange that a programmer's mistake can prevent the device from booting in such a case? – JohnyTex Jan 12 '17 at 13:35
  • 1
    _"Why is it important that `HomeInterceptorActivity` is the top activity for BOOT_COMPLETED to be sent?"_ Not 100% sure (need to look at the sources), but it seems in case of a "home" `Activity` an additional condition is checked and/or a method is called after `onResume()` returns (right before the `Activity` becomes visible)... _"Is it not strange that a programmer's mistake can prevent the device from booting in such a case?"_ Partially agree - you kinda breaking the lifecycle here, `onResume()` has a dedicated intention mentioned above... – Onik Jan 12 '17 at 14:42
  • Do you think it will be safe to start another activity directly in onResume() only after BOOT_COMPLETED has been received? Can I otherwise, somehow post (delay) the start of another activity to make sure that this "addictional condition / method" is run before the new Activity is started? – JohnyTex Jan 18 '17 at 11:06
  • If I start an Activity within a Handler#postDelayed() with a 1 sec delay it works which seems to indicate you are right. Something needs to be finished. Just don't know what or what to wait for. – JohnyTex Jan 18 '17 at 13:42
  • _"Something needs to be finished"_ The view hierarchy has to be rendered (become visible), it happens at some point after `onResume()` returns. You should start a new `Activity` either when views [laied out](http://stackoverflow.com/questions/22972022/why-does-calling-getwidth-on-a-view-in-onresume-return-0/22972145#22972145) or within another thread, whose [`Runnable` will be handled](http://stackoverflow.com/questions/22972022/why-does-calling-getwidth-on-a-view-in-onresume-return-0/22972181#22972181) once the views are rendered or use a `Handler` delayed. – Onik Jan 18 '17 at 14:00
  • Seems Android could stall startActivity() itself then instead of having me find out if it is ready? So retrieving rootLayout guarantees the views are laid out properly? – JohnyTex Jan 18 '17 at 16:46
  • _"Seems Android could stall startActivity() itself then instead of having me find out if it is ready?"_ Sorry, it's not clear to me what you mean. _"So retrieving rootLayout guarantees the views are laid out properly?"_ Each of the three approaches suggested should work. – Onik Jan 18 '17 at 17:11

0 Answers0