I'm trying to start an activity from a service I had already acquired the lock for as follows:
Intent i = new Intent(context, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(i);
The activity manifest is declared as follows:
<activity
android:name=".MyActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard|navigation"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:screenOrientation="nosensor"
android:showOnLockScreen="true"
android:taskAffinity=""
android:theme="@style/MyTheme" />
And finally, on onCreate()
or on onAttachedToWindow()
(I tried on both), I add the following flags:
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
The problem is that the first time I call startActivity()
from my service, the screen turns on but the activity itself does not show up. It shows the lock screen instead. Every subsequent call of startActivity()
works properly but I can't find a reason for this odd behavior.
I tried already suggestions to get a full wakelock instead of partial, change the flags and values in the manifest according to the following SO answers:
- Android Activity Not Showing When Screen is Woken Up and Lock Screen Not Disabling
- how to unlock the screen when BroadcastReceiver is called?
- Programmatically turn screen on in android
- Android Galaxy S4 -- Activity that is visible over lock screen
Note that my theme is not a dialog but a fullscreen activity.
Any other ideas?