Hi,
I have a project where I usq sql and keyvaluestore libraries.
Since I'm using one instantiated object from the whole project, I'm thinking about the best (most optimal) way to use. I've thought using a code module like this:
So, wherever I need to use the SQL object, I get it using MyModule.GetSQL function. But since I'm not familiar with the code module life cycle, I'm wondering what happen with the oSQL object after the call ends or after the calling activity/service module ends. The idea is to get oSQL instantiated as long as possible, right?
Same thing with the KeyValueStore object (not defined yet)
Is a code module the right option to do something like this? Is this way a good option?
Thank you very much!
I have a project where I usq sql and keyvaluestore libraries.
Since I'm using one instantiated object from the whole project, I'm thinking about the best (most optimal) way to use. I've thought using a code module like this:
B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private oSQL As SQL
End Sub
Public Sub GetSQL() As SQL
Dim rSQL As SQL
Try
If oSQL=Null OR oSQL.IsInitialized=False Then
If File.Exists(File.DirInternal,"database.db") = False Then
File.Copy(File.DirAssets,"database.db",File.DirInternal,"database.db")
End If
oSQL.Initialize(File.DirInternal, "database.db", False)
End If
rSQL=oSQL
Catch
'doing stuff
End Try
Return rSQL
End Sub
So, wherever I need to use the SQL object, I get it using MyModule.GetSQL function. But since I'm not familiar with the code module life cycle, I'm wondering what happen with the oSQL object after the call ends or after the calling activity/service module ends. The idea is to get oSQL instantiated as long as possible, right?
Same thing with the KeyValueStore object (not defined yet)
Is a code module the right option to do something like this? Is this way a good option?
Thank you very much!