Android Question [SOLVED] Close activity and remove from stack.

Serge Bertet

Active Member
Licensed User
Hi all, an easy question but no way to find an answer ...

When the user receive a notification and clicks on it the app jumps in an activity.
This breaks the normal cycle of activities.
Is there a way to remove this activity from the stack?
B4X:
Sub Activity_Pause(UserClosed As Boolean)
    if starter.Notified And UserClosed then B4XPages.ClosePageAndRemove(Me) ' or something like that ...
End Sub

Thank you.

Serge.
 
Last edited:

Serge Bertet

Active Member
Licensed User
Exactly, but why is that a problem?
You are right, I think I manage that case the wrong way, my fault...
B4X:
Private Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        StartActivity(Main) ' I should not do that, just close the current activity
        Return True
    End If
    Return False
End Sub
Thank you to point that ... sometimes your are looking for problem where there is no.
 
Upvote 0

Serge Bertet

Active Member
Licensed User
OK, I found a way to go back to my previous activity (before notification click):
B4X:
Private Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Activity.Finish
        Return True ' don't know if needed
    End If
    Return False ' don't know if needed
End Sub
without this sub the back button does nothing.
 
Upvote 0
Top