Android Question Object Not Initialized - Frustrating Intermittent Error (Memory Leak?)

yonson

Active Member
Licensed User
Longtime User
Hi

I have a frustrating problem occurring across all my apps, and I assume its some mistake I'm making in my coding approach. Any help much appreciated.

My apps work absolutely fine, but then intermittently (typically when returning from a long period of the app being paused / background state) I get this Java Runtime Exception:-

Object should first be Intialized (Map). Continue?

This is happening in all my activities and occurs for a variety of different variable types. A sample of the relevant code is :-

Sub Globals
Dim info As Map
End Sub
Sub Activity_Create(FirstTime AsBoolean)
Activity.LoadLayout("SummaryView")
info.Initialize
info=EstablishmentInterface.getEstablishmentFullInfo(Main.iyork_establishment_id,Null)

etc etc

Is there anything obviously wrong here? As you can see the very first thing I do after loading my layout in Activity_create is initiaze the info variable, however is there something I'm missing? My concern is that there are no errors when first launching etc, it requires the app to go into a long paused state before it manifests itself, so I assume its something to do with memory being reclaimed by another resource.

Have tried all sorts of workarounds but really want to get to the bottom of this. Any ideas? Can provide the complete code but its a huge app so don't want to complicate things!

Thanks
 

yonson

Active Member
Licensed User
Longtime User
hi
apologies I thought I'd replied to this - no I checked the code and it comes back initialiazed even if its an empty map.

Its also doing it for all sorts of other object types - database SQL objects etc. Any other thoughts?
Thanks so much
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Generate the code in debug and get the relevant b4a line number for the statement that is erroring. It's probably a line of code or sub that you aren't considering.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I think you'll find it's to do with the application lifecycle. When it's paused for a long time it can be destroyed by the OS, if you are not storing Activity Objects in the Map you can dim it as a Process Variable.

Otherwise you'll need to store and re-populate your persistant variables. That's not the full story have a look at the lifecycle tutorial here.
 
Upvote 0

yonson

Active Member
Licensed User
Longtime User
Hi Steve, yes that sounds like exactly the problem, I'll have a review of the code over the next few days. appreciate you taking the time to help me.
Thanks
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi Steve, yes that sounds like exactly the problem, I'll have a review of the code over the next few days. appreciate you taking the time to help me.
Thanks
To solve this problem, I usually create a module that initializes all my variables. At the beginning of each activity, I check whether one of these variables still contains a given value. If not, then I know that all my data have been wiped out by the OS. I just call my module to re-initialize everything. Some of these data are saved to a file each time a Pause event is raised, thus I can restore a previous state.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…