Hi guys, I have an odd problem that I'm not sure how to fix and I'm hoping someone here can shed some light on it.
I have a simple activity with a listview (ListView1). The ListView was created using the designer.
In the Globals section I have:
Dim ListView1 As ListView
My Activity_Create looks like this:
And my resume like this:
It is the LoadList method that loads the data into the XList.
This works fine, except sometimes when I leave the app and then return back to it after an arbitrary period of time, I get an error saying that ListView1 is not initialised. I assume that Android has decided that it needs to free up memory and has nuked the ListView control.
I realise I can call the Initialize method on the listview like so:
ListView1.Initialize("ListView1")
But I don't understand:
* Why does the error occur in the first place? If my Activity_Create method calls
Activity.LoadLayout("XList")
which I assume initializes the ListView, why isn't it being initialized when I return to the app?
* In what event should I put:
ListView1.Initialize("ListView1")
In create? In resume?
* If I need to do this for listviews, what about other controls like buttons, panels, etc?
* What is best practice of initializing objects. Is it not safe to rely on the designer and LoadActivity to initialize objects?
Any help would be appreciated.
I have a simple activity with a listview (ListView1). The ListView was created using the designer.
In the Globals section I have:
Dim ListView1 As ListView
My Activity_Create looks like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("XList")
PanelHeading.LoadLayout("HeadingButton")
End Sub
And my resume like this:
B4X:
Sub Activity_Resume
LoadList
End Sub
It is the LoadList method that loads the data into the XList.
This works fine, except sometimes when I leave the app and then return back to it after an arbitrary period of time, I get an error saying that ListView1 is not initialised. I assume that Android has decided that it needs to free up memory and has nuked the ListView control.
I realise I can call the Initialize method on the listview like so:
ListView1.Initialize("ListView1")
But I don't understand:
* Why does the error occur in the first place? If my Activity_Create method calls
Activity.LoadLayout("XList")
which I assume initializes the ListView, why isn't it being initialized when I return to the app?
* In what event should I put:
ListView1.Initialize("ListView1")
In create? In resume?
* If I need to do this for listviews, what about other controls like buttons, panels, etc?
* What is best practice of initializing objects. Is it not safe to rely on the designer and LoadActivity to initialize objects?
Any help would be appreciated.
Last edited: