Android Question Disable the Power button.

vecino

Well-Known Member
Licensed User
Longtime User
Hello, is it possible to disable the Power button? Or at least have a delay of a few seconds before the screen turns off when it's pressed.

The issue is that I have some customers who press to process sales, and before the application finishes processing and notifies that it's ready for another sale, some customers press the Power button, the screen turns off, and some processes remain incomplete.

How can I solve this?
Thank you.
 

DonManfred

Expert
Licensed User
Longtime User
Hello, is it possible to disable the Power button?
You can not Disable it and you can not even detect pressing the Button.

If the user presses it you app will go into background.
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thanks for the information, I was afraid that is the situation.
Any idea how to control such cases?
Some users don't have the patience to wait even half a second, which is how long it takes for the “Sale processed” message (toast) to appear.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Any idea how to control such cases?
It's not a B4XPages app, right?

I think then you have to make your process in a service instead of in an Activity
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, it is not B4XPages, that application is many years old.
Anyway, as you say, I use a service to process sales, it sends them to a remote computer and it works without problems.
The problem with them turning off the screen is with the graphical environment that the user sees, because when they turn the screen back on, what is displayed does not correspond to the real situation of the processed sale.
Then various random “weird” situations occur.
I tell them not to turn it off, or to configure in settings to turn it off automatically after 5 seconds, for example.
Or wait half a second, but no, they prefer to turn it off quickly.
I have done tests and, basically, to do what these users do, it is necessary to hit the “Process sale” button and the “turn off device” button at almost the same time.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Then I think you should handle such situation in Activity_Resume and maybe you should make something on Activity_Pause

 
Upvote 1

vecino

Well-Known Member
Licensed User
Longtime User
That's what I had thought:
B4X:
Sub Activity_Pause(UserClosed As Boolean).
  Log(“UserClosed :”&UserClosed)
  ...
  ...
End Sub

But I don't quite understand how “UserClosed” works because if I press the power button to turn off the screen it tells me:

UserClosed :false
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
If you check the Graphical Life image I've sent you, it says at the bottom:

"UserClosed will be true if (and only if) the user presses the BACK key or you call Activity.Finish"

Probably you will have to refresh your UI in activity_resume instead of in Activity_Create
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Maybe this could be helpful:

 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thanks, friends, surely moving some processes to “Resume” will solve the problem.

The other option is to send an electric shock to the user's finger if they press the power button while the application is processing.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Save the information necessary to complete the sale in Activity_Pause and in Activity_Resume check to see if there is an incomplete sale and if so complete it. You can easily save things between invocations of your app using the internal KeyValueStore2 library.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Actually Erel now recommends using the KeyValueStore b4xlib instead of KeyValueStore2 - confusing isn't it o_O
This library is named KeyValueStore. There is an older library named KeyValueStore2. Don't confuse between the two. It is recommended to use this one.
It is an internal library now
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Perhaps you can detect that the user clicks off in an unwanted way, and when they restore the application, it presents a message for 10 seconds, 'restoring the system', this way, in 1 day you will be able to get them out of the habit. (This, until Erel implements the electric shock)
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Perhaps you can detect that the user clicks off in an unwanted way, and when they restore the application, it presents a message for 10 seconds, 'restoring the system', this way, in 1 day you will be able to get them out of the habit. (This, until Erel implements the electric shock)
😁
This is a very good idea
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
. . . . before the application finishes processing and notifies that it's ready for another sale . . . .
Rather that waiting until the transaction is complete before presenting a message would it be better, at the start of the transaction, to present a pop-up that says "Transaction is being processed - please wait." and removing it when it is safe to continue?
 
Upvote 0
Top