Android Question Close interface, leave service running?

GuyBooth

Active Member
Licensed User
Longtime User
My app starts as a service using Start on Boot.
The user may open an interface by clicking on the app icon.
When he/she has finished, I want the interface to close but leave the service running. Currently, the service is destroyed when the interface is closed using the back key.
How do I close the interface but leave the service running?
 

GuyBooth

Active Member
Licensed User
Longtime User
Hmmm … I think maybe just calling
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Activity_Pause(True)
    Return False
End Sub
will do the trick.
I do like to stick with B4A code when I can.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Useless code. Activity_Pause is callback function. Does nothing. Return False in Activity_KeyPress means default reaction. There is no need to describe.
If you press "Back" button, your app will go to background anyway.

moveTaskToBack is useful, when the app sends itself to background (for example, in Button_Click subroutine).
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
I think I only need
Useless code. Activity_Pause is callback function. Does nothing. Return False in Activity_KeyPress means default reaction. There is no need to describe.
If you press "Back" button, your app will go to background anyway.
Without code in Activity_Keypress the service shuts down. Seems I just need
B4X:
' Close the activity. Services will still run when required.
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode= KeyCodes.KEYCODE_BACK Then
        Return False
    End If   
    Return True
End Sub
 
Upvote 0
Top