Android Question Keep on the timer tick event when the user push on/off hardware button

PierPaduan

Active Member
Licensed User
Longtime User
Hi.
I have an activity with a countdown timer that must continue to count even if the user push the on/off hardware button to turn off screen.
At this moment the timer stop if the light is off.
In addition the screen must turn on when the countdown is near to zero.

Please someone can help me?
Thanks a Lot.
 

PierPaduan

Active Member
Licensed User
Longtime User
Thanks Don, but I don't have experience about services, may you give to me some more instruction, or an example?
Thanks a Lot.
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Ok Erel, Thanks, I tried with some good results.
I have created a service that I start from an activity.
In the service I detect screenoff event.
In this event i call startserviceat and with keepalive(true) I turn on again the screen, but the screen saver turns on and my activity remain in Pause.
How can I avoid the screen saver ?

The code of the service in the following...
Thanks a lot.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim PE As PhoneEvents
    Dim nNotify As Notification 
    Dim pw1 As PhoneWakeState

End Sub
Sub Service_Create
    nNotify.Initialize
    nNotify.Icon = "icon"
    nNotify.SetInfo("Welding", "Tap to open welding", Welding)
    nNotify.Sound=False
    nNotify.Vibrate=False
    nNotify.Light=False
    nNotify.OnGoingEvent=True
    Service.StartForeground(1,nNotify)

    PE.Initialize ("PE")
  
End Sub
Sub Service_Start (StartingIntent As Intent)
    pw1.KeepAlive (True)

End Sub
Sub Service_Destroy

End Sub
Sub PE_screenoff (Intent As Intent)
    StartServiceAt("", DateTime.Now, True)
End Sub
 
Last edited:
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Thanks Erel for your help and your patience.
The code tags are in place now.

What I exactly want to do is the following:
I have my activity running. If the user push the on/off button I want that the screen remain turned on and my activity remain running on the screen.

In other words I would like to disable the on/off button.

I handle the screenoff event to turn the screen on again. And this works (the screen remain off for less than one second), but doing this, my activity goes in pause state and the telephone show me the locked screen. If I unlock the screen manually, my activity return to resumed state.

I hope you can help me.
Thank you very much.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I think you cannot disable the on/off button.

And, btw, if i have an app installed which ignores my wish to shut off my phone and let the app and screen running ....
I´ll remove this fu**ing app faster than it need to install it.

IT`S MY DEVICE!!! And if i want to shut it off then it should do what i want! WHEN i want! Not when a App want.

I hope you (and any other here (including me!)) did not find a way to do so

Sor sure, that´s my personal meaning about this
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Thanks Don for your opinion.

I think that I didn't explained very well. I don't want to disable the opportunity to shut the phone off.

Example: In the Camera app in my phone (samsung corby), if I fast push on/off button, the screen remain on, but the touch screen and the hardware buttons are locked. If I long push the on/off button the OS ask me if I want to shut off or not the phone.

I want to do a very similar thing. When one specific activity in my app is active it must remain active if someone fast push the on/off button, but if the push is a long push, the OS will ask if shut off or not. To exit from this activity I use the back button.

Any idea is welcome.
Thanks.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…