I have declared a Private variable on a certain page. Its value is set to 1. The variable changes when I press either of 2 buttons that can either increment it or decrement it. For argument's sake, the variable stops on the value of 5 when I exit the page. When I reselect the page, that value of 5 is retained. I don't know why. The page is being re-initialized. I am not checking to see if it was previously initialized. I'm just reinitializing it in the same way that it was first created. I tried removing the page from the stack when I exit it; but it still initializes and retains the value of 5. What's happening here? I just want the whole page to go away without any remnant of it and recall it. Clearly, I don't understand something about how pages are managed.
This is the main advantage of B4XPages: they are never destroyed, so the only routine that is executed each time reopening them is the B4XPage_Appear (Initialize and B4XPage_Created will be executed only once).
This is the advantage of B4XPages: they are never destroyed, so the only routine that is executed after closing and reopening them is the B4XPage_Appear (Initialize and B4XPage_Created will be executed only once).
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private PageChartsAndGraphs As Page
Private btnNext, btnPrevious As Button
Private xui As XUI
'My Charts
Private PieChartEmployers As xChart
Private PieChart2Employers As xChart
Private PieChartCashCredit As xChart
Private LineChartAvgTips As xChart
Private BarChartBestTipDays As xChart
Private StackedBarChartActualVsMin As xChart
Private BarChartEarningsPerHour As xChart
Private PieChartTipRetention As xChart
Private PieChartMileage As xChart
Private BarChartBestTipHours As xChart
Private BarChartDeliveriesByHour As xChart
Private BarChartDeliveriesByDay As xChart
Private pnlCharts As Panel
Private labelExplanation As Label
Private nCashTipRatio As Double
Private nCreditTipRatio As Double
Private SelectedChart = 1 As Int 'Never resets to 1 after page is exited, then redisplayed'
Private iad As InterstitialAd
End Sub
Public Sub ShowChartsAndGraphs
PageChartsAndGraphs.Initialize("PageChartsAndGraphs")
ResetLayout 'Localize
'Set gradiant color to panel
GlobalFunctions.SetTheme(pnlCharts, False)
Main.NavControl.ShowPage(PageChartsAndGraphs)
ShowChart(SelectedChart)
If Main.UseAds Then
Private iad As InterstitialAd
If Main.UseTestAds Then
iad.Initialize("iad","ca-app-pub-3940256099942544/4411468910") 'Testing ID
Else
iad.Initialize("iad","ca-app-pub-3033958332466628/7153345605")
End If
iad.RequestAd
End If
End Sub
Private Sub btnNext_click
SelectedChart = SelectedChart + 1
If SelectedChart >= 1 And SelectedChart <= 12 Then
ShowChart(SelectedChart)
End If
End Sub
Private Sub btnPrevious_click
SelectedChart = SelectedChart - 1
If SelectedChart >= 1 And SelectedChart <= 12 Then
ShowChart(SelectedChart)
End If
End Sub
Private Sub PageChartsAndGraphs_Disappear
Main.NavControl.SetPagesStack(Array (MainScreen.PageMain)) 'Tried to kill chart page to no avail'
SelectedChart = 1 'Without resetting to chart 1, page reappears at the same chart number that was displayed when page was exited'
MainScreen.CloseMenu
End Sub
Private Sub ShowChart(pChart As Int)
'Hide all charts except the next one
PieChartEmployers.Visible = False
PieChart2Employers.Visible = False
PieChartCashCredit.Visible = False
LineChartAvgTips.Visible = False
BarChartBestTipDays.Visible = False
StackedBarChartActualVsMin.Visible = False
BarChartEarningsPerHour.Visible = False
PieChartTipRetention.Visible = False
PieChartMileage.Visible = False
BarChartBestTipHours.Visible = False
BarChartDeliveriesByHour.Visible = False
BarChartDeliveriesByDay .Visible = False
Select pChart
Case 1
btnPrevious.Visible = False
btnNext.Visible = True
PieChartEmployers.Visible = True
CreatePieDataEmployers
Case 2
btnPrevious.Visible = True
PieChart2Employers.Visible = True
CreatePieData2Employers
Case 3
PieChartCashCredit.Visible = True
CreatePieDataCashCredit
Case 4
LineChartAvgTips.Visible = True
CreateLineChartAvgTips
Case 5
BarChartBestTipDays.Visible = True
CreateBarChartBestTipDays
Case 6
StackedBarChartActualVsMin.Visible = True
CreateStackedBarChartActualVsMin
Case 7
BarChartEarningsPerHour.Visible = True
CreateBarChartEarningsPerHour
Case 8
PieChartTipRetention.Visible = True
CreatePieChartTipRetention
Case 9
PieChartMileage.Visible = True
CreatePieChartMileage
Case 10
BarChartBestTipHours.Visible = True
CreateBarChartBestTipHours
Case 11
btnNext.Visible = True
BarChartDeliveriesByHour.Visible = True
CreateBarChartDeliveriesByHour
Case 12
btnPrevious.Visible = True
btnNext.Visible = False
BarChartDeliveriesByDay.Visible = True
CreateBarChartDeliveriesByDay
End Select
End Sub
Private Sub iad_Ready (Success As Boolean)
If Main.UseAds Then
If Success Then
iad.Show(PageChartsAndGraphs) 'show ad
' iad.RequestAd 'request a new one!
Else
Log("ad not ready to show")
End If
End If
End Sub
Private Sub ResetLayout
PageChartsAndGraphs.RootPanel.RemoveAllViews
PageChartsAndGraphs.RootPanel.LoadLayout("MultiCharts")
PageChartsAndGraphs.Title = Main.Localize.Localize("Charts and Graphs") 'List(PageTitle).Get(0)
Main.Localize.LocalizeLayout(PageChartsAndGraphs.RootPanel)
End Sub
Project is too large to attach. I emailed it to you. I suspect that whatever is going on here is also related to another issue. If you select Charts and Graphs from the main menu, leave page, then select Alerts, the table view does not fill the screen. If I leave the partially displayed Alerts screen, then reselect it, the entire table is displayed. The screen is not being re-initialized.
When you re-initialize a page, previous Page (UIViewController) will be removed.
But variables, declared in Process_Globals, do not have any relation to UIViewController instance.
To understand how b4i works, imagine following code
B4X:
Sub Something
Dim i As Int
Dim Page As Object
...
End Sub
Page re-initializing is equal to assignment a new value to Page variable. Meanwhile i will not be changed.
So, you need to reset global variables 'manually'.
When you re-initialize a page, previous Page (UIViewController) will be removed.
But variables, declared in Process_Globals, do not have any relation to UIViewController instance.
To understand how b4i works, imagine following code
B4X:
Sub Something
Dim i As Int
Dim Page As Object
...
End Sub
Page re-initializing is equal to assignment a new value to Page variable. Meanwhile i will not be changed.
So, you need to reset global variables 'manually'.
Erel, I’m good now. I understand the variable issue and I was missing the page resize event that caused my table view not to display properly after I left my Charts and Graphs page.