Android Question Stuck partial wake locks (background)

cucvalencia

Member
Licensed User
Hello everyone, I just saw this error in the Play Console and I have no idea how to solve it.

Bad behavior - Stuck partial wake locks (background) - 0.24%

I think it has to be related to the PhoneWakeState and the Sub Activity_Resume or the Sub Activity_Pause in case someone knew how I could solve it.

Thanks

B4X:
Sub Process_Globals
    Dim PWS As PhoneWakeState
End Sub

Sub Globals
    Dim AcSf As AcceleratedSurface
    Dim SP As SoundPool
    Dim MP_music_menu, MP_music_game As MediaPlayer
End Sub

Sub Activity_Resume
    AcSf.StartRegularUpdateAndDraw(16)
    PWS.KeepAlive(True)
    If room = room_juego Then
        If MP_music_game.IsPlaying = False Then
            MP_music_game.Position = 0
            MP_music_game.Play
            MP_music_game.SetVolume(0.15, 0.15)
        End If
    Else If room = room_menu Then
        If hay_musica = 1 Then
            If MP_music_menu.IsPlaying = False Then
                MP_music_menu.Position = 0
                MP_music_menu.Play
                MP_music_menu.SetVolume(0.09, 0.09)
            End If
        End If
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    AcSf.StopRegularDraw
    PWS.ReleaseKeepAlive
    If MP_music_menu.IsPlaying Then MP_music_menu.Pause
    If MP_music_game.IsPlaying Then MP_music_game.Pause
    If UserClosed Then
        SP.Release
        If MP_music_menu.IsPlaying Then MP_music_menu.Stop
        If MP_music_game.IsPlaying Then MP_music_game.Stop
    End If
End Sub
 

JohnC

Expert
Licensed User
Longtime User
Is the PSW.KeepAlive(True) that you have in your above code the *ONLY* keepalive in your app?

It looks like your app is a Game, so that it shouldn't be doing anything in the background right?

You can try adding a:
B4X:
Log("KeepAlive")
Right before the PWS.KeepAlive(True) in your Activity_Resume sub above.

And then place:
B4X:
Log("Release")
Right before the PWS.ReleaseKeepAlive in your Activity_Pause sub above.

Then operate your app and switch away from it and then back to it and switch away again.

The LOG entries should stay in sync so then when you switch away from your app, the last LOG entry should say "RELEASE".

If you see a "KEEPALIVE" and your app is in the background, then that means something triggered your Activity_Resume sometime after it ran the PWS.Release line and you need to find out why.
 
Upvote 0

cucvalencia

Member
Licensed User
Thank you, but all is right. There is only one PSW.KeepAlive(True) and the last LOG is "RELEASE" when switch away from the app. I never see "KEEPALIVE" when the app is in the background.

I will remove the PWS code as you said: " it shouldn't be doing anything in the background " and I will see what happens...

Thank you JohnC
 
Upvote 0
Top