B4J Question B4XPage_Background not firing/how do I know when the page loses focus.

MrKim

Well-Known Member
Licensed User
Longtime User
B4J 10.2 win 11
B4X:
Sub B4XPage_Background
    Log("B4XPage_Background-MP")
End Sub
The only time the B4XPage_Background event fires is when I close the app. I added it to one Erel's examples just to make sure I didn't mess something up.
I also tried
B4X:
Private Sub B4XPage_Background
    Log("B4XPage_Background-MP")   
End Sub
I tested this with MainPage and others with the same result.
The goal is to know when the current page loses focus. I don't really care how.
 
Solution
See this post for more information about the events: https://www.b4x.com/android/forum/t...or-managing-multiple-pages.118901/post-744867

You can add a focus changed event with JavaObject:
B4X:
    Dim jfrm As JavaObject = B4XPages.GetNativeParent(Me)
    Dim FocusEvent As Object = jfrm.CreateEvent("javafx.beans.value.ChangeListener", "Focus", Null)
    jfrm.GetFieldJO("stage").RunMethodJO("focusedProperty", Null).RunMethod("addListener", Array(FocusEvent))


Private Sub Focus_Event (MethodName As String, Args() As Object) As Object
    If MethodName = "changed" Then
        Dim focus As Boolean = Args(2)
        Log(B4XPages.GetPageId(Me) & " focus: " & focus)
    End If...

Erel

B4X founder
Staff member
Licensed User
Longtime User
See this post for more information about the events: https://www.b4x.com/android/forum/t...or-managing-multiple-pages.118901/post-744867

You can add a focus changed event with JavaObject:
B4X:
    Dim jfrm As JavaObject = B4XPages.GetNativeParent(Me)
    Dim FocusEvent As Object = jfrm.CreateEvent("javafx.beans.value.ChangeListener", "Focus", Null)
    jfrm.GetFieldJO("stage").RunMethodJO("focusedProperty", Null).RunMethod("addListener", Array(FocusEvent))


Private Sub Focus_Event (MethodName As String, Args() As Object) As Object
    If MethodName = "changed" Then
        Dim focus As Boolean = Args(2)
        Log(B4XPages.GetPageId(Me) & " focus: " & focus)
    End If
    Return Null
End Sub
 
Upvote 0
Solution
Top