Android Alarm - Activity Sometimes Remains Black After Keyguard Dismissal












2














I have an alarm activity, that launches from a service as a Full-Screen Notification Intent. The problem is that sometimes, the activity will remains black until I turn it off and on again.



Now, although the screen is black, the views respond to the touch



If I try to take a screenshot, I suddenly see the activity, and if I turn the screen off and on again, everything is working as expected.



I can't seem to reproduce this on my debug build, but it does happen to me on the "production" build from time to time. (Let's say 1/5 times)



It will happen in the morning in between snoozes, but never on the first alarm. (as far as I noticed)



Any idea on what is causing this, or how to reproduce this would help immensely.



Videos of the weirdness:



Responsive black screen



Turn off, and on again



Trying to take a screenshot



This is basically how I launch the activity:



val builder = NotificationCompat.Builder(context, NotificationChannels.CHANNEL_ALARM_SERVICE)
...
// set intent
val alarmIntent = Intent(context, AlarmActivity::class.java)
alarmIntent.putExtra(IntentExtras.KEY_ID, alarm.id)
builder.setFullScreenIntent(PendingIntent.getActivity(context, RequestCodes.REQUEST_CODE_ALARM_ACTIVITY, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT), true)
...
startForeground(...)


This is how I unlock the screen in the Activity's onCreate() method



public class ScreenUnlockerUtil {

public static void unlockScreen(BaseActivity activity) {

activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
// in addition to flags
activity.setShowWhenLocked(true);
activity.setTurnScreenOn(true);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
if (keyguardManager != null) {
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
@Override
public void onDismissError() {
super.onDismissError();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Error"));
}

@Override
public void onDismissSucceeded() {
super.onDismissSucceeded();
Timber.d("Keyguard Dismiss Success");
}

@Override
public void onDismissCancelled() {
super.onDismissCancelled();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Cancelled"));
}
});
}
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}


}
}


Edit 1: I'm not seeing any reports from my device regarding keyguard dismissal cancellation or error.



Edit 2: This is all happening on a Pixel 2 XL. Not some random crappy phone.










share|improve this question
























  • I have the same problem Nokia 6.1 Android 9. I am not using dismiss keyguard, so it is clearly related to activity.setShowWhenLocked(true); activity.setTurnScreenOn(true);
    – Dominik K
    Dec 26 '18 at 19:03












  • @DominikK Apparently it also doesn't show the Activity when locked on random Samsung devices for our users.
    – sofakingforever
    Dec 27 '18 at 7:12










  • I am not sure about the samsung devices. Which API level are we talking about on those devices?
    – Dominik K
    Dec 27 '18 at 9:29










  • @DominikK Nothing below API 21, but I'm not sure which version those users are running.
    – sofakingforever
    Dec 27 '18 at 15:11










  • Do you know which types of samsung phones the problem occurs on like on the Galaxy S9, S8, Note,...
    – Dominik K
    Dec 28 '18 at 9:38
















2














I have an alarm activity, that launches from a service as a Full-Screen Notification Intent. The problem is that sometimes, the activity will remains black until I turn it off and on again.



Now, although the screen is black, the views respond to the touch



If I try to take a screenshot, I suddenly see the activity, and if I turn the screen off and on again, everything is working as expected.



I can't seem to reproduce this on my debug build, but it does happen to me on the "production" build from time to time. (Let's say 1/5 times)



It will happen in the morning in between snoozes, but never on the first alarm. (as far as I noticed)



Any idea on what is causing this, or how to reproduce this would help immensely.



Videos of the weirdness:



Responsive black screen



Turn off, and on again



Trying to take a screenshot



This is basically how I launch the activity:



val builder = NotificationCompat.Builder(context, NotificationChannels.CHANNEL_ALARM_SERVICE)
...
// set intent
val alarmIntent = Intent(context, AlarmActivity::class.java)
alarmIntent.putExtra(IntentExtras.KEY_ID, alarm.id)
builder.setFullScreenIntent(PendingIntent.getActivity(context, RequestCodes.REQUEST_CODE_ALARM_ACTIVITY, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT), true)
...
startForeground(...)


This is how I unlock the screen in the Activity's onCreate() method



public class ScreenUnlockerUtil {

public static void unlockScreen(BaseActivity activity) {

activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
// in addition to flags
activity.setShowWhenLocked(true);
activity.setTurnScreenOn(true);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
if (keyguardManager != null) {
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
@Override
public void onDismissError() {
super.onDismissError();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Error"));
}

@Override
public void onDismissSucceeded() {
super.onDismissSucceeded();
Timber.d("Keyguard Dismiss Success");
}

@Override
public void onDismissCancelled() {
super.onDismissCancelled();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Cancelled"));
}
});
}
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}


}
}


Edit 1: I'm not seeing any reports from my device regarding keyguard dismissal cancellation or error.



Edit 2: This is all happening on a Pixel 2 XL. Not some random crappy phone.










share|improve this question
























  • I have the same problem Nokia 6.1 Android 9. I am not using dismiss keyguard, so it is clearly related to activity.setShowWhenLocked(true); activity.setTurnScreenOn(true);
    – Dominik K
    Dec 26 '18 at 19:03












  • @DominikK Apparently it also doesn't show the Activity when locked on random Samsung devices for our users.
    – sofakingforever
    Dec 27 '18 at 7:12










  • I am not sure about the samsung devices. Which API level are we talking about on those devices?
    – Dominik K
    Dec 27 '18 at 9:29










  • @DominikK Nothing below API 21, but I'm not sure which version those users are running.
    – sofakingforever
    Dec 27 '18 at 15:11










  • Do you know which types of samsung phones the problem occurs on like on the Galaxy S9, S8, Note,...
    – Dominik K
    Dec 28 '18 at 9:38














2












2








2


1





I have an alarm activity, that launches from a service as a Full-Screen Notification Intent. The problem is that sometimes, the activity will remains black until I turn it off and on again.



Now, although the screen is black, the views respond to the touch



If I try to take a screenshot, I suddenly see the activity, and if I turn the screen off and on again, everything is working as expected.



I can't seem to reproduce this on my debug build, but it does happen to me on the "production" build from time to time. (Let's say 1/5 times)



It will happen in the morning in between snoozes, but never on the first alarm. (as far as I noticed)



Any idea on what is causing this, or how to reproduce this would help immensely.



Videos of the weirdness:



Responsive black screen



Turn off, and on again



Trying to take a screenshot



This is basically how I launch the activity:



val builder = NotificationCompat.Builder(context, NotificationChannels.CHANNEL_ALARM_SERVICE)
...
// set intent
val alarmIntent = Intent(context, AlarmActivity::class.java)
alarmIntent.putExtra(IntentExtras.KEY_ID, alarm.id)
builder.setFullScreenIntent(PendingIntent.getActivity(context, RequestCodes.REQUEST_CODE_ALARM_ACTIVITY, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT), true)
...
startForeground(...)


This is how I unlock the screen in the Activity's onCreate() method



public class ScreenUnlockerUtil {

public static void unlockScreen(BaseActivity activity) {

activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
// in addition to flags
activity.setShowWhenLocked(true);
activity.setTurnScreenOn(true);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
if (keyguardManager != null) {
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
@Override
public void onDismissError() {
super.onDismissError();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Error"));
}

@Override
public void onDismissSucceeded() {
super.onDismissSucceeded();
Timber.d("Keyguard Dismiss Success");
}

@Override
public void onDismissCancelled() {
super.onDismissCancelled();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Cancelled"));
}
});
}
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}


}
}


Edit 1: I'm not seeing any reports from my device regarding keyguard dismissal cancellation or error.



Edit 2: This is all happening on a Pixel 2 XL. Not some random crappy phone.










share|improve this question















I have an alarm activity, that launches from a service as a Full-Screen Notification Intent. The problem is that sometimes, the activity will remains black until I turn it off and on again.



Now, although the screen is black, the views respond to the touch



If I try to take a screenshot, I suddenly see the activity, and if I turn the screen off and on again, everything is working as expected.



I can't seem to reproduce this on my debug build, but it does happen to me on the "production" build from time to time. (Let's say 1/5 times)



It will happen in the morning in between snoozes, but never on the first alarm. (as far as I noticed)



Any idea on what is causing this, or how to reproduce this would help immensely.



Videos of the weirdness:



Responsive black screen



Turn off, and on again



Trying to take a screenshot



This is basically how I launch the activity:



val builder = NotificationCompat.Builder(context, NotificationChannels.CHANNEL_ALARM_SERVICE)
...
// set intent
val alarmIntent = Intent(context, AlarmActivity::class.java)
alarmIntent.putExtra(IntentExtras.KEY_ID, alarm.id)
builder.setFullScreenIntent(PendingIntent.getActivity(context, RequestCodes.REQUEST_CODE_ALARM_ACTIVITY, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT), true)
...
startForeground(...)


This is how I unlock the screen in the Activity's onCreate() method



public class ScreenUnlockerUtil {

public static void unlockScreen(BaseActivity activity) {

activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
// in addition to flags
activity.setShowWhenLocked(true);
activity.setTurnScreenOn(true);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
if (keyguardManager != null) {
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
@Override
public void onDismissError() {
super.onDismissError();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Error"));
}

@Override
public void onDismissSucceeded() {
super.onDismissSucceeded();
Timber.d("Keyguard Dismiss Success");
}

@Override
public void onDismissCancelled() {
super.onDismissCancelled();
ExceptionHandlerWrapper.reportException(new Exception("Keyguard Dismiss Cancelled"));
}
});
}
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}


}
}


Edit 1: I'm not seeing any reports from my device regarding keyguard dismissal cancellation or error.



Edit 2: This is all happening on a Pixel 2 XL. Not some random crappy phone.







android android-activity alarmmanager android-notifications android-doze






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 19:32

























asked Nov 14 '18 at 19:22









sofakingforever

382211




382211












  • I have the same problem Nokia 6.1 Android 9. I am not using dismiss keyguard, so it is clearly related to activity.setShowWhenLocked(true); activity.setTurnScreenOn(true);
    – Dominik K
    Dec 26 '18 at 19:03












  • @DominikK Apparently it also doesn't show the Activity when locked on random Samsung devices for our users.
    – sofakingforever
    Dec 27 '18 at 7:12










  • I am not sure about the samsung devices. Which API level are we talking about on those devices?
    – Dominik K
    Dec 27 '18 at 9:29










  • @DominikK Nothing below API 21, but I'm not sure which version those users are running.
    – sofakingforever
    Dec 27 '18 at 15:11










  • Do you know which types of samsung phones the problem occurs on like on the Galaxy S9, S8, Note,...
    – Dominik K
    Dec 28 '18 at 9:38


















  • I have the same problem Nokia 6.1 Android 9. I am not using dismiss keyguard, so it is clearly related to activity.setShowWhenLocked(true); activity.setTurnScreenOn(true);
    – Dominik K
    Dec 26 '18 at 19:03












  • @DominikK Apparently it also doesn't show the Activity when locked on random Samsung devices for our users.
    – sofakingforever
    Dec 27 '18 at 7:12










  • I am not sure about the samsung devices. Which API level are we talking about on those devices?
    – Dominik K
    Dec 27 '18 at 9:29










  • @DominikK Nothing below API 21, but I'm not sure which version those users are running.
    – sofakingforever
    Dec 27 '18 at 15:11










  • Do you know which types of samsung phones the problem occurs on like on the Galaxy S9, S8, Note,...
    – Dominik K
    Dec 28 '18 at 9:38
















I have the same problem Nokia 6.1 Android 9. I am not using dismiss keyguard, so it is clearly related to activity.setShowWhenLocked(true); activity.setTurnScreenOn(true);
– Dominik K
Dec 26 '18 at 19:03






I have the same problem Nokia 6.1 Android 9. I am not using dismiss keyguard, so it is clearly related to activity.setShowWhenLocked(true); activity.setTurnScreenOn(true);
– Dominik K
Dec 26 '18 at 19:03














@DominikK Apparently it also doesn't show the Activity when locked on random Samsung devices for our users.
– sofakingforever
Dec 27 '18 at 7:12




@DominikK Apparently it also doesn't show the Activity when locked on random Samsung devices for our users.
– sofakingforever
Dec 27 '18 at 7:12












I am not sure about the samsung devices. Which API level are we talking about on those devices?
– Dominik K
Dec 27 '18 at 9:29




I am not sure about the samsung devices. Which API level are we talking about on those devices?
– Dominik K
Dec 27 '18 at 9:29












@DominikK Nothing below API 21, but I'm not sure which version those users are running.
– sofakingforever
Dec 27 '18 at 15:11




@DominikK Nothing below API 21, but I'm not sure which version those users are running.
– sofakingforever
Dec 27 '18 at 15:11












Do you know which types of samsung phones the problem occurs on like on the Galaxy S9, S8, Note,...
– Dominik K
Dec 28 '18 at 9:38




Do you know which types of samsung phones the problem occurs on like on the Galaxy S9, S8, Note,...
– Dominik K
Dec 28 '18 at 9:38












1 Answer
1






active

oldest

votes


















1














A very strange problem, I couldn't find the exact reason for it. But I could come up with a very stable solution, just add the following parameters to your manifest file and it should work. I have tried it like 15 times and never had the problem again, while I had it 1 out of 5 times with the code solution.



Don't forget to delete the code lines in your onCreate.



    <activity android:name=".AlertActivity"
android:showWhenLocked="true"
android:turnScreenOn="true">
</activity>





share|improve this answer



















  • 1




    I'll be sure to check it out! thanks!
    – sofakingforever
    Dec 27 '18 at 7:18










  • I hope it works for you too, I still didn't run into the issue again.
    – Dominik K
    Dec 27 '18 at 9:27











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307421%2fandroid-alarm-activity-sometimes-remains-black-after-keyguard-dismissal%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














A very strange problem, I couldn't find the exact reason for it. But I could come up with a very stable solution, just add the following parameters to your manifest file and it should work. I have tried it like 15 times and never had the problem again, while I had it 1 out of 5 times with the code solution.



Don't forget to delete the code lines in your onCreate.



    <activity android:name=".AlertActivity"
android:showWhenLocked="true"
android:turnScreenOn="true">
</activity>





share|improve this answer



















  • 1




    I'll be sure to check it out! thanks!
    – sofakingforever
    Dec 27 '18 at 7:18










  • I hope it works for you too, I still didn't run into the issue again.
    – Dominik K
    Dec 27 '18 at 9:27
















1














A very strange problem, I couldn't find the exact reason for it. But I could come up with a very stable solution, just add the following parameters to your manifest file and it should work. I have tried it like 15 times and never had the problem again, while I had it 1 out of 5 times with the code solution.



Don't forget to delete the code lines in your onCreate.



    <activity android:name=".AlertActivity"
android:showWhenLocked="true"
android:turnScreenOn="true">
</activity>





share|improve this answer



















  • 1




    I'll be sure to check it out! thanks!
    – sofakingforever
    Dec 27 '18 at 7:18










  • I hope it works for you too, I still didn't run into the issue again.
    – Dominik K
    Dec 27 '18 at 9:27














1












1








1






A very strange problem, I couldn't find the exact reason for it. But I could come up with a very stable solution, just add the following parameters to your manifest file and it should work. I have tried it like 15 times and never had the problem again, while I had it 1 out of 5 times with the code solution.



Don't forget to delete the code lines in your onCreate.



    <activity android:name=".AlertActivity"
android:showWhenLocked="true"
android:turnScreenOn="true">
</activity>





share|improve this answer














A very strange problem, I couldn't find the exact reason for it. But I could come up with a very stable solution, just add the following parameters to your manifest file and it should work. I have tried it like 15 times and never had the problem again, while I had it 1 out of 5 times with the code solution.



Don't forget to delete the code lines in your onCreate.



    <activity android:name=".AlertActivity"
android:showWhenLocked="true"
android:turnScreenOn="true">
</activity>






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 26 '18 at 22:52

























answered Dec 26 '18 at 19:13









Dominik K

81113




81113








  • 1




    I'll be sure to check it out! thanks!
    – sofakingforever
    Dec 27 '18 at 7:18










  • I hope it works for you too, I still didn't run into the issue again.
    – Dominik K
    Dec 27 '18 at 9:27














  • 1




    I'll be sure to check it out! thanks!
    – sofakingforever
    Dec 27 '18 at 7:18










  • I hope it works for you too, I still didn't run into the issue again.
    – Dominik K
    Dec 27 '18 at 9:27








1




1




I'll be sure to check it out! thanks!
– sofakingforever
Dec 27 '18 at 7:18




I'll be sure to check it out! thanks!
– sofakingforever
Dec 27 '18 at 7:18












I hope it works for you too, I still didn't run into the issue again.
– Dominik K
Dec 27 '18 at 9:27




I hope it works for you too, I still didn't run into the issue again.
– Dominik K
Dec 27 '18 at 9:27


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307421%2fandroid-alarm-activity-sometimes-remains-black-after-keyguard-dismissal%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word