I am trying to start an action from a service that I already purchased to block, 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 phenomenon of activity 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 onAttachedToWindow() (I tried both), 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 is not displayed. Instead, a lock screen is displayed. Each subsequent call to startActivity() works correctly, but I cannot find the reason for this odd behavior.
I already tried the suggestions to get the full wakelock instead of partial, change the flags and values ββin the manifest according to the following SO answers:
- Android activity is not displayed when the screen accelerates and the screen lock does not turn off
- How to unlock the screen when calling BroadcastReceiver?
- Programmatically enable screen in android
- Android Galaxy S4 - activity that is visible on the lock screen
Please note that my topic is not a dialog, but a full-screen one.
Any other ideas?
android android-activity
Ricardo lage
source share