PartialLock didn't keep service alive?

susu

Well-Known Member
Licensed User
Longtime User
Hi, I create a service that will turn screen on when an event raise. After 5 seconds, I want to turn screen off and service need to keep running. Because I don't know how to turn screen on/off automatically so I use PhoneWakeState to do it. I thought PhoneWakeState.PartialLock can keep service running but it not. Any suggestion for me? Thank you.

B4X:
Dim ph As PhoneWakeState
Dim t as Timer
t.Initialize("t", 5000)

Sub Service_Start (StartingIntent As Intent)
      ' Some code
   ph.PartialLock
   Service.StartForeground(1, noti)
      ' Some code
End Sub

' Some code to handle event


Sub TurnScreenOn
      ph.ReleaseKeepAlive
      ph.KeepAlive(True)     ' Turn screen on
      t.Enabled = True
End Sub

Sub t_tick
      TurnScreenOff     ' Turn screen off after 5 seconds
End Sub

Sub TurnScreenOff
      ph.ReleaseKeepAlive   ' Turn screen off
      ph.PartialLock      ' Try to keep service running but... failed!
End Sub
 

susu

Well-Known Member
Licensed User
Longtime User
How do you see that the service is not running?

1. The service didn't handle when event raised.
2. The notification icon is gone (I set notification OnGoing).
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
1. Event capture by a library. It worked perfect when I press power button if there NOT ph.ReleaseKeepAlive in TurnScreenOff sub.
2. No, it didn't disappear after 5 seconds. It gone after some time.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Yes, I disabled timer in t_tick but it didn't fix the issue.

I noticed that only Samsung phone with Android 2.3.6 got this error:

Case 1: The screen is on => Event always raised.
Case 2: I press power button to turn screen off => Event raised, the screen turn on automatically.
Case 3: After case 2 about 5 minutes, it didn't work. (I thought the service was killed by OS). I press power button to turn screen on, open activity by click on notification icon => it still didn't work. I need to stop and restart service to make it work again (So the OS really killed the service).

HTC phone with Android 2.3.4 worked correctly.

Erel, if you don't understand what I said, I can send you my project code
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
The service capture "whistle" event by using a library.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
If the problem is in library, why the service works correctly on Android 2.3.4?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…