Android alarm running press home button block UI (Lollipop) - android

I have an weird situation regarding an alarm app. I have an app that is "awake" the all night and at certain point the alarm starts and is the user press the back button or a button in the User Interface (UI) the alarm sound stops and move to the next activity (until here everything is Ok!)
The scenario is: The screen is deemed, the alarm starts so the activity is launched and the user press the power button. After it press the power button again (the activity starts again) and press Home button.
Pre-Lollipop
The app is running in background and the alarm is still ringing(normal behavior)
Lollipop
The screen becomes black, the user can't do anything on his phone until he reboots and the alarm is ringing
Did you have experienced this before? I see there are lots of black screen issues with lollipop but I only see "solutions" from user point of view and I would like to make my app avoiding this issue.

This issue was related with the keyguard, I was disabling the keyguard when the intent of the alarm was received because I wanted to disable the lock screen, but I realized the best place to do that is in the method onResume.
So I move the disable keyguard to onResume and enable keyguard to onPause and that made the trick

Related

Android onStop gets called right after tap home button

I have a quick question regarding a basic feature of Android. It's clear that onPause is called when the screen is partially visible. Further onStop is supposedly called only when the screen is no longer in either the foreground or background.
Strangely however when I press the square home button on my phone onStop is called each time in my activity. Even though the activity screen is partially visible I see a log after 0.5 - 1 second of showing in the background. This causes onRestart to be called when returning from a simple pause. Since I am attempting to show an ad here this is slightly problematic. I tested on my Samsung Galaxy A51 and Pixel 3 XL API 30 emulator with the same result.
Currently I am wondering why this method is called here and would like to fix my understanding. I could very well be missing something obvious and apologize if so (low memory condition?). Below are screenshots with the system log and activity lifecycle diagram. I show before any taps, with the log window after 1 tap and then the log window after returning and tapping a 2nd time.
What is this pause button? If you mean it power button or home button, there should never be a hardware button directly connected Activity's lifecycle onPause.
When you press a power button or home button, it goes lock screen or Recents screen, in either of these scenarios your app is certainly stopped (onPause then onStop) rather than just suspended (only onPause).
It seems that going directly onResume from onPause may be rather rare case.
onPause()
In Android 7.0 (API level 24) or higher, multiple apps run in multi-window mode. Because only one of the apps (windows) has focus at any time, the system pauses all of the other apps.
A new, semi-transparent activity (such as a dialog) opens. As long as the activity is still partially visible but not in focus, it remains paused.
About the latter scenario, you can find an answer on StackOverflow.
So, if your app isn't coded to cause a direct onPause to onResume lifecycle, your app should go onStop right after onPause as a normal behavior.

Alarm rings, options displayed, then user presses home

I have written an alarm program which works nicely in most regards. When the alarm rings the user is presented with three options to select:
Stop
Snooze
Reschedule
The user then selects their choice, the alarm stops and what happens next depends on which option they selected.
But now I have a problem. Say the alarm goes off and the user accidentally presses the home button whilst fishing their phone out of their pocket. Now the alarm is still ringing, but the app is no longer in display! I don't know how to avoid this scenario. Any ideas?
If you use activity as dialog, and if home button is pressed causing activity to close, you can simply put alarm's stop method in onstop() method of activity.

How can I turn on screen when my app running in background of a program?

I have a program which runs another program.
I want to prevent the user from pressing the power button to turn the screen off and if the user turned the screen off , my program turns it back on!
For this I implement a broadcast receiver that catches the screen off event, then it calls a service to run an activity and in this activity I will turn the screen on and that activity then runs my desired program ...
This plan works fine when I'm not running that app and the screen goes on when the user presses the power button! But when my desired application is running, my program does not work properly in the background! Sometimes it turns the screen on, sometimes it doesn't!

Android Lock Screen appears behind home screen occasionally

Android 4+
We're developing a lock screen app (not a widget). The app listens for SCREEN_OFF, and generates the activity, so that when SCREEN_ON is received, the user sees the activity in front of the security features using FLAG_SHOW_WHEN_LOCKED.
We've found that on rare occasions around 1 in every 50 to 100 times, the activity appears behind the Home screen rather than in front of the lock screen. We cannot replicate the issue, and it doesn't appear to happen when connected for debugging (I've sat and locked/unlocked my phone and not seen it, then taken the cable out and it happens in the next few times).
The activity appears to display over the wallpaper, with the home screen icons over the top of the activity.
3 questions:
1) Is it possible to "listen" for when the home screen gets started so that we could just finish() the activity at that point?
2) Is it possible to ensure that the activity runs over the lock screen all the time?
3) How would you test this to try to replicate the fault? I cannot figure out why it does it at all and cannot replicate it.
TIA

WakeLock.release() switches off screen even if the user was interacting with the app

My app wakes the phone from standby and turns on the screen (SCREEN_BRIGHT_WAKE_LOCK). I can't use the WindowManager-flags approach, as my app may already be running in the background.
The problem is that once the user dismisses my app and the WakeLock is released, the screen turns off immediately, even if the user was interacting with the app (or the homescreen, which briefly shows while the app is being closed).
Would using the ON_AFTER_RELEASE-flag help?
Yes, you want to use the ON_AFTER_RELEASE flag.
When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

Categories

Resources