I am playing with the new concept of pages and got stuck using sql databases.
1) declaring a sql db and initializing in the starter or main page gives me the error that the db cannot be opened (despite using android.permission.WRITE_EXTERNAL_STORAGE)
2) initializing the db in the B4Xresults gives the error java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method)
My question: where should i define and initialize a sql database that can be accessible by all pages ?
You can also Dim the SQL in the B4XMainPage, Public SQL1 As SQL, and initialize it in the B4XPage_Created routine.
And access it in other modules with: B4XPages.MainPage.SQL1.
I have only had a quick play with B4XPages ... but previously in B4A , it was recommended to declare and initialize SQL (and other objects) in the starter service.
I can understand the thinking declaring SQL object in B4XMainPage etc, in a Cross Platform project (and maybe doing away with the starter service to reduce some code.)
But in a solely B4A app (with B4XPages) , would it not still be the recommended way to go ? (using Starter Service for declaring public objects etc.)
I don't know why @Phayao encountered the errors but surely if the Object is Declared and Called correctly all should be good .... No ?
In this special case the problem was that the runtime permission was missing prior to initialze SQL:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim rp As RuntimePermissions
' check write permissions BEFORE sql.ini
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
wait for Activity_PermissionResult(Permision As String, Result As Boolean)
SQL1.Initialize(DBDir,DBFile,False)
Dim pm As B4XPagesManager
pm.Initialize(Activity)
Therefore the initialization of the sql did not work.