Android Question How to pause activity ?

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

The app has multiply activities. Typiically I process KeyCodes.KEYCODE_BACK in Activity_KeyUp and control sequence of activities.
But there is "main" activity. When user clicks 'back' button I want simply to pause an activity (to hide it). How to do this ?

If to do nothing, back buttons returns previuos activity.
 

Peter Simpson

Expert
Licensed User
Longtime User
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Peter --
I don't want to exit. I want to make the same action as Android, when you have one activity and press back button.
Typically it's not neccessary to process something - activity becomes background, the app is alive.

In my case sequence is following. Initial activity (A) calls real main activity (B) and dies (I don't need activity A any more, so I execute Activity.Finish).
Problem happends in activity B, when user clicks "Back". When I do not process KeyPress, dead activity A appears. Meanwhile I want to send activity B to sleep. Something like SleepActivity (B). But how ?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Exactly, just modify the back key capture to do absolutely nothing instead of exiting the app. You have to use your imagination a bit here and not just expect the exact code to be sitting there waiting for you :p
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Peter --
In my case sequence is following. Initial activity (A) calls real main activity (B) and dies (I don't need activity A any more, so I execute Activity.Finish).
Problem happends in activity B, when user clicks "Back". When I do not process KeyPress, dead activity A appears. Meanwhile I want to send activity B to sleep. Something like SleepActivity (B). But how ?
Where are you placing the activity.finish? Can you share this part of the code?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Thanx for attention. It seems to me I found, what I need.

B4X:
Sub Activity_KeyPress (intKeyCode As Int) As Boolean

         If intKeyCode = KeyCodes.KEYCODE_BACK Then
             Dim jo As JavaObject
            jo.InitializeContext
            jo.RunMethod("moveTaskToBack", Array(True))          
            Return True
        Else
            Return False
        End If

End Sub

Meanwhile it's not clear, why app does not work like expected. Probably, due to services.
 
Last edited:
Upvote 0
Top