I can do this but wonder what the simplest (least amount of code) way is to do this for a large project.
RBS
RBS
Strange question.I can do this but wonder what the simplest (least amount of code) way is to do this for a large project.
RBS
> Strange question.Strange question.
I assume you mean how to detect if page x's Appear event is triggered by closing page y.
"Appear" will be triggered in that case or by the Show method; if instead the page will be displayed because the app will return to the foreground, you will have to handle the Foreground event.
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private Const MY_PAGE_ID As String = "PageOne"
Private ShowCalled As Boolean
End Sub
Private Sub B4XPage_Appear
If ShowCalled Then
Else
End If
ShowCalled = False
End Sub
Public Sub Show
ShowCalled = True
B4XPages.ShowPage(MY_PAGE_ID)
End Sub
Public ClosingPageID As String
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private Const MY_PAGE_ID As String = "PageOne"
End Sub
Private Sub B4XPage_Appear
If B4XPages.MainPage.ClosingPageID.Length > 0 Then
Else
End If
B4XPages.MainPage.ClosingPageID = ""
End Sub
Private Sub B4XPage_Disappear
B4XPages.MainPage.ClosingPageID = MY_PAGE_ID
End Sub
OK, I did something similar (I think):One way could be this (not a few lines):
B4X:Sub Class_Globals Private Root As B4XView 'ignore Private xui As XUI 'ignore Private Const MY_PAGE_ID As String = "PageOne" Private ShowCalled As Boolean End Sub
B4X:Private Sub B4XPage_Appear If ShowCalled Then Else End If ShowCalled = False End Sub
Calling that Show method instead of B4XPages.ShowPage(...).B4X:Public Sub Show ShowCalled = True B4XPages.ShowPage(MY_PAGE_ID) End Sub
Another could be to create a public variable in the B4XMainPage, setting its value to the id of the page you just closed:
B4XMainPage:Public ClosingPageID As String
PageX:Sub Class_Globals Private Root As B4XView 'ignore Private xui As XUI 'ignore Private Const MY_PAGE_ID As String = "PageOne" End Sub
PageX:Private Sub B4XPage_Appear If B4XPages.MainPage.ClosingPageID.Length > 0 Then Else End If B4XPages.MainPage.ClosingPageID = "" End Sub
PageX:Private Sub B4XPage_Disappear B4XPages.MainPage.ClosingPageID = MY_PAGE_ID End Sub
'In B4XMainPage, ClassGlobals:
Public mapB4XPagesShow As Map 'Will be initialized in Public Sub Initialize
'In Sub ShowPage in B4XMainPage:
mapB4XPagesShow.Put(iPage, 1) 'iPage is an integer number identifying the various B4XPages
'In the various B4XPages in Sub B4XPageAppear (cMP is a class instance of B4XMainPage):
If 0 = cMP.mapB4XPagesShow.GetDefault(iPageCode, 0) Then 'this means this Sub was triggered by B4XPages.ClosePage
'Run some code here
Else
'this means this Sub was triggered by B4XPages.ShowPage
cMP.mapB4XPagesShow.Put(iPageCode, 0) 'return to the default
End If
Private Sub WaitForValue
Wait For (B4XPages.MainPage.Page2.Show) Complete (Result As Object)
If Result <> Null Then
' ...
End If
End Sub
Public Sub Show As ResumableSub
Wait For Value_Selected (Result As Object)
Return Result
End If
Private Sub B4XPage_CloseRequest As ResumableSub
CallSubDelayed2(Me, "Value_Selected", Null)
Return True
End Sub
Private Sub CustomListView_ItemClick(Index As Int, Value As Object)
B4XPages.ClosePage(Me)
CallSubDelayed2(Me, "Value_Selected", Value)
End Sub
Not sure how to use this and it seems more code than what I got now.Depending on what you're trying to do, you could potentially use resumable subs.
page1:Private Sub WaitForValue Wait For (B4XPages.MainPage.Page2.Show) Complete (Result As Object) If Result <> Null Then ' ... End If End Sub
page2:Public Sub Show As ResumableSub Wait For Value_Selected (Result As Object) Return Result End If Private Sub B4XPage_CloseRequest As ResumableSub CallSubDelayed2(Me, "Value_Selected", Null) Return True End Sub Private Sub CustomListView_ItemClick(Index As Int, Value As Object) B4XPages.ClosePage(Me) CallSubDelayed2(Me, "Value_Selected", Value) End Sub
Sub PageAppearedFromClosePage As Boolean
Dim bResult As Boolean
bResult = (0 = mapB4XPagesShow.GetDefault(miPageCode, 0))
If bResult = False Then
mapB4XPagesShow.Put(miPageCode, 0) 'so return to the default
End If
Return bResult
End Sub
If cMP.PageAppearedFromClosePage Then 'this means this Sub was triggered by B4XPages.ClosePage
'run some page code
End If