I'm using the following flags in onAttachedToWindow()
to show my Activity
above the keyguard:
FLAG_DISMISS_KEYGUARD | FLAG_SHOW_WHEN_LOCKED | FLAG_TURN_SCREEN_ON
This works fine, however, when launching my activity from a background service while the screen was off, the keyguard sometimes shows for 1-2 seconds before my app is displayed. This happens particularly on slower phones (or in low memory situations). I find this strange, since my understanding was that onAttachedToWindow()
is called after onCreate()
/onResume()
, so all the "heavy work" should already have been completed when the flags mentioned above are being set? Is there any way to only show my Activity
once it has been completely set up?
onResume()
? – ChurlonCreate()
andonResume()
are pretty resource-intensive, they e.g. re-color bitmaps and dynamically set up the UI. This is unfortunately needed and can't be carried out asynchronously, as the user should see the final UI right from the beginning. – LulululuabourgThread.sleep(1000)
in youronCreate()
andonResume()
? From my understanding of the order in whichonCreate()
,onResume()
andonAttachedToWindow()
are called, this shouldn't make any difference (it should just delay the Activity from popping up, rather than leading to the keyguard being shown for 2 seconds) – LulululuabourgThread.sleep(1000)
call to bothonCreate()
andonResume()
. On my Rezound & Ally, I get a black screen as it sleeps on both create & resume before displaying. However, on my Xperia Active (running 4.0.4), I hit a loop before the device wakes up, and sometimes I do indeed get the keyguard prior to the view! You're correct thatonAttachedToWindow()
fires in the lifecycle after theonCreate()
,onStart()
, andonResume()
callbacks fire. – KatydidWindow.addFlags()
call? Your launcher activity, or another? And are you callingfinish()
anywhere? – Katydidboth my onCreate() and onResume() are pretty resource-intensive, they e.g. re-color bitmaps
. You will get even ANR if you will try to block UI for more that ~5 sec. Instead you must do heavy lifting of bitmaps in background thread. Or prepare your bitmaps in your service, save them to sdcard and in yourActivity
just read them from sd card (of course from background thread). Reading bitmap won't take long so hopefully user won't notice anything. – FellatioColorFilter
to an existing bitmap, so I'm not actually doing anything where loading the bitmap from storage would be quicker. When I launch the activity from a button (i.e. not from the background and without the keyguard showing), the UI-thread is blocked for maybe 1 second max. – LulululuabourgWindow.addFlags()
call is a "random" activity, i.e. not the launcher activity. I'm callingfinish()
after the user has "acknowledged" my activity, but not in any unusual places (likeonPause()
, for example). The activity awakes the screen at a number of points during the day, so my app's other activities are probably no longer in the activity stack in most instances. – Lulululuabourgfinish()
in the same activity that calledaddFlags()
, the keyguard would not function properly. Moving the keyguard flag to another activity or removing the call tofinish()
fixed the issue entirely. – Katydid