Android Question Log Out

Hello everyone!

I'm building an android app with B4X and I want to create a Log Out Button on every screen.
The way I thought of it to work is this:
  1. Call the LogIn page (B4XPages.ShowPage("MainPage"))
  2. The page that the user was on disappears.
  3. the B4XPage_Disappear() Sub is called.
  4. In that sub I delete every action (Activity1.Finish()) and return the screen to it's initial form, forwhen the user logs in again and wants to use it.
The problem is that when I call the B4XPage_Disappear() Sub the app crashes.
There is obviously a problem with the way I handle the Activity.
Here are some code snippets you may find useful:

Activity Related Code:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore

    Public dialog As B4XDialog
    Public token As String
    Private ScanHereMC As B4XView
    Private NewPaletteBtnMC As B4XView
    Private QuantityMC As B4XView
    Private AcceptInputBtnMC As B4XView
    Private i As Int = 0
    Public url As String
    Private PanelMC As B4XView
    Private LogOutMainPage As B4XView
  
    Private LogIn As B4XMainPage
    Private Activity1 As Activity
End Sub

Public Sub Initialize As Object
    Return Me
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
'   should i use Activity1 instead of Root1 here?
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Lay_MoveContainer")
    ScanHereMC.RequestFocus()
    Dim cs As CSBuilder
    cs.Initialize
    cs.Image(LoadBitmap(File.DirAssets, "image002.png"), 40dip, 40dip, True).Append(CRLF).Append("     Μετακίνηση Περιεκτών").Alignment("ALIGN_NORMAL")
    cs.PopAll
    TitleSplit.Text = cs
  
    LogIn.Initialize
    B4XPages.AddPageAndCreate("MainPage", LogIn)
End Sub

Private Sub B4XPage_Disappear()
    Try
        Activity1.Finish()
    Catch
        Log(LastException)
    End Try
End Sub

The app crashes even though I used a try-catch statement and couldn't find any work arounds, even though I tried some things.
I saw in the Booklets that there are some problems with using "Activity" when writing B4X.

Finally if there is another (possibly better) routine for the LogOut, please let me know.
 
Top