B4J Question close a process

Pelky

Active Member
Licensed User
Longtime User
I would like to fully close a process when I have finished with it. What I find is that if I make a choice - from a menu - load a process and layout and then finish with it (exit) back to the menu and then take that choice again certain parts of the process are not run again. This is a problem as a file may have been updated and the process needs to get that change. A reporting Date for example. This works fine the first time around but when I go back?

The process needs to start fresh.

I have tried - B4XPages.ClosePage(Me) - and that closes the process but the underlying process remains.

Is there a way to kill the process without killing the application entirely.
 

Pelky

Active Member
Licensed User
Longtime User
aah sorry didnt saw this. you will need to explain what do you mean by process. do you mean a page? a form? or a shell?
Thank you for your response - much appreciated.
I am a bit old for this game and so I dont use the terms you may be familiar with. My apologies for that.

What I mean is:- I have an app that has many class modules that are started by choices made using button selections etc. on one module.
Lets say - reporting module has 5 buttons (choices) for different reports. On the reporting module you select the date for the reports and write that to an sql database. On button selection Each of the different modules reads the report date record and sets up the report layout and tables based on that date. It then displays the report and If the user is happy they can select to print the report. There is no other user interaction other than the print option. The user would then select to close and return to the Reporting Module (Menu). (If I use exit application then the entire application dies). If the user then changes the reporting date (maybe previous Date choice was in error) and selects the same report module the module does not read the database and continues with the "first time run" details so the report date selection is the same as the previous one.

I need for the report modules to run as "first Time" evert time so I need to be able to close/clear the selected report module.

I hope that I have made that clearer - Once again I thank you for your response
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The terms are indeed incorrect.
You are asking about closing a form (=page).

I need for the report modules to run as "first Time" evert time so I need to be able to close/clear the selected report module.
The correct way to do it is to add a sub that removes all views, reset the variables state and loads the layout.
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
The terms are indeed incorrect.
You are asking about closing a form (=page).


The correct way to do it is to add a sub that removes all views, reset the variables state and loads the layout.
I take it this is done prior to opening the new layout? If so then how do I go about closing the views and resetting the state?
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    ResetPage
End Sub

Public Sub ResetPage
    Root.RemoveAllViews
    Root.LoadLayout("MainPage")
    SomeImportantVariable = 0
End Sub

B4X:
OtherPage.Reset
B4XPage.Show("OtherPage")
Thank you Erel....
I tried ResetPage sub and it worked the first time - I put a log to show it ran - when I exited and then tried it again it did not
run that Sub again - the log showed that -
I then tried the otherpage reset substituting my Name ie;

GateReport.Reset
B4XPages.ShowPage("GateReport")

the GateReport is not defined and so I get an error

Below is the code for the GateReport Module

B4X:
Public Sub ResetPage
    Root.RemoveAllViews
'    Root.LoadLayout("MainPage")
'    SomeImportantVariable = 0
    Log("removed views")
End Sub



'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    ''    'load the layout to Root
    ResetPage
    Dim w As Form = B4XPages.GetNativeParent(Me)
    w.WindowWidth = 600
    w.WindowHeight = 842
    w.Resizable = True

    Private fx As JFX
    Root.IsInitialized
    repMainForm = B4XPages.GetNativeParent(Me)
    repMainForm.RootPane.LoadLayout("GateReport") 'Load the layout file.
    repMainForm.Show
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
B4X:
Dim pg As GateReport = B4XPages.GetPage("GateReport")
pg.ResetPage
B4XPages.ShowPage("GateReport")
Once Again Thank you for your assistance.
I did try that and I got the error:-

Reporting - 79: Unknown member: resetpage
Reporting - 85: Unknown member: resetpage

I am sorry to trouble you with this but it is important to the running of all my reports
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
I have seen where my error is - this pg.ResetPage is the SUB within the GateReport.
I have corrected that and it shows no error - however
if I have Root.RemoveAllViews within that I get an error -

Initial Tables Exist and initialized
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
*** reporting: B4XPage_Created [mainpage]
in B4XPage Created
*** reporting: B4XPage_Appear [mainpage]
*** reporting: B4XPage_Resize [mainpage, reporting]
gatereport._vvvvvvvvvvvvvvvvvvvvvv4 (java line: 338)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.B4XViewWrapper.asPaneWrapper(B4XViewWrapper.java:133)
at anywheresoftware.b4a.objects.B4XViewWrapper.RemoveAllViews(B4XViewWrapper.java:533)
at b4j.example.gatereport._vvvvvvvvvvvvvvvvvvvvvv4(gatereport.java:338)
at b4j.example.reporting._btngatevisitors_click(reporting.java:252)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
Can you upload the project (ctrl + click on the export link at the top of B4XMainPage) ?
Sorry to trouble you again but i was wondering what is the maximum size that i can upload. I was thinking that
I could remove a lot of the application and only upload the relevant parts - would that be okay?
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
My guess:
Use B4XPages.AddPageAndCreate when you add the pages and it will not crash.
Thank you for your response.. my system/app does not crash if I don't use Root.RemoveAllViews - I really just want to be able to load a page and it starts as first time every time. I don't want to have to have the user select a reporting date every time.
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
My guess:
Use B4XPages.AddPageAndCreate when you add the pages and it will not crash.
I have written some code to show what I have done and hope this shows the problem better. - B4XPage class module

Loading the layout and show the date from a SQL read:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private Button1 As B4XView
    Private DateLabel As B4XView
    Private Pane1 As B4XView
    Private ReportDateLabel As B4XView
    Public DB As SQL
    Public DBFileDir As String = "..\Legals"
    Public DBFileName As String = "LegalVisits.db"
    Public ReportDate As Long
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    
    DB.InitializeSQLite(DBFileDir, DBFileName, True)
    If LastException.IsInitialized Then Log(LastException.Message)
    Log("Initial Tables Exist and initialized")
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("test")
    testing
End Sub
Private Sub testing
    ReportDate = DB.ExecQuerySingleResult("SELECT ReportingFromDate FROM ReportsDate")
    Log("ReportDate = "&ReportDate)
    DateLabel.Text = DateTime.Date(ReportDate)
    ReportDateLabel.Text = DateTime.Date(ReportDate)
    Log("In activity Resume")
End Sub

Private Sub Button1_Click
    Try
        ReportDate = DB.ExecQuerySingleResult("SELECT ReportingFromDate FROM ReportsDate")
    Catch
        xui.MsgboxAsync("did not read again", "testing")
    End Try
    DateLabel.Text = DateTime.Date(ReportDate)
    ReportDateLabel.Text = DateTime.Date(ReportDate)
End Sub

now what happens is when I run this the first time it does the read from the SQL Database and displays the date - no problem.
I then come out and change the SQL Database reporting date record.
I then go back in to the module the previous date is shown (Before the update). If I then click on Button1 it updates the Date shown to the correct date (Updated Record) .. I can understand that the testing sub call only runs once because the B4XPage_Created sub is only run once.

The problem is I need the changed date and I really don't want to have to use a Button to read it - I would like it to happen every time I
select the module.

I hope I have made it clearer.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I think you want to refresh the data in the B4XPage_Appear Sub.
After you close a page, the page with old data is still there. When you call B4XPage.ShowPage(".."), the B4XPage_Appear Sub in the page is called.
That is where one usually updates the page dynamically - or refreshes or even load a different layout (after removing all views).

I recommend writing a small project without a database component and test various scenarios. For example:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private count As Int
    Private label1 As Label
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("page1")
End Sub

Private Sub B4XPage_Appear
    count = count + 1
    If count = 1 Then
        label1.Text = "Appear first time"
    Else
        label1.Text = "Appearance #" & count
    End If
End Sub
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
I think you want to refresh the data in the B4XPage_Appear Sub.
After you close a page, the page with old data is still there. When you call B4XPage.ShowPage(".."), the B4XPage_Appear Sub in the page is called.
That is where one usually updates the page dynamically - or refreshes or even load a different layout (after removing all views).

I recommend writing a small project without a database component and test various scenarios. For example:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private count As Int
    Private label1 As Label
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("page1")
End Sub

Private Sub B4XPage_Appear
    count = count + 1
    If count = 1 Then
        label1.Text = "Appear first time"
    Else
        label1.Text = "Appearance #" & count
    End If
End Sub
I really don't know how to thank you. That did the job! .... thank you so very very much..
Is there somewhere I an find all these B4XPage_??????? s ....
Once again Thank You
 
Upvote 0
Top