Android Question Start Activity when phone is locked not working

Graeme Tacon

Member
Licensed User
Longtime User
Hi,

I've got an Alarm Clock app, which was working fine until recently. Now, when the alarm triggers, the app is not showing the 'Snooze' screen. I know the service is triggering at the right time, as I can see from the log it keeps that that is happening, but it is not 'waking' the phone up and throwing the screen.

I have the code below, which is performed in the Activity_Create sub of my Snooze Activity.

B4X:
    Dim pws As PhoneWakeState
    Dim r As Reflector
    r.Target = r.GetActivity
    r.Target = r.RunMethod("getWindow")
    r.RunMethod2("addFlags", 6815872, "java.lang.int")
    pws.KeepAlive(False)
    pws.PartialLock

I'm using B4A v8.3 and have a SGS9 with Android 8.0.0. The targetSDK is set to 28 in my app.

What am I missing ?
 

Semen Matusovskiy

Well-Known Member
Licensed User
There is a lot of changes in Oreo.
It's impossible to say something without short sample, which demonstrates how exactly you start an activity.

If you really have 8.1 (API 27) due to updates, you need to add
SetActivityAttribute (main, android:showWhenLocked, "true")
SetActivityAttribute (main, android:turnScreenOn, "true")
to manifest or to call corresponding functions

I combined your code with https://www.b4x.com/android/forum/t...d-how-to-wake-up-this-app-from-service.96792/

After pressing Power button (which locks screen), the app sleeps 15 seconds and appears again.
The code assumes API 27+. Works normally on my phone (Android 8.1.0).
 

Attachments

  • test.zip
    8.6 KB · Views: 518
Last edited:
Upvote 1

Graeme Tacon

Member
Licensed User
Longtime User
Hi
Thanks for the test app and comments, I've finally gotten around to having a look at it.
The test app works fine and I've discovered that my app also works, if I don't swipe it from the recent apps list.
Your app does still continue to work if swiped from the recent apps list though.
So, I'm a little confused.
 
Upvote 0
Top