Android Question Activity_KeyPress in service intent combination?

Daniel-White

Active Member
Licensed User
Longtime User
Hello everybody,

I have the next code, it is working fine. my idea is detect when the user press too much time the hardware button (Volumen UP) and trigger the toasMessageShow("EUREKA",true).

That is working fine when the APP is running. Now the question is, how can I put the APP to work that feature KeyPress, when the APP executed the Activity.finished. It is not running so the KeyPress will not running neither of course :eek:.

will I need to put a service? mmm that will consume a lot cpu ? or we can use an intent like service for SMS TEXT intent? it will only run when detect a new SMS, so I guess we can do something similar with KeyPress and intent?

I guess to save battery the route is go with "intent" I am looking to put a service in background and run only when detect the Volumen UP

Any light or similar example in the forum will be very appreciated.
B4X:
'Detect Volume UP
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    Log(KeyCode)
    If KeyCode = KeyCodes.KEYCODE_VOLUME_UP  Then
    
        ContadorDeVolumen=ContadorDeVolumen+1
        Log("ContadorDeVolumen="&ContadorDeVolumen)
        If ContadorDeVolumen >= 10 Then
              ToastMessageShow("EUREKA",True)
        End If
        ToastMessageShow("Volume UP",False)
      '  Return True
    Else
         ContadorDeVolumen=0
    End If
End Sub
 
Last edited:
Top