Android Question Error restart app.

LéonE

Member
Licensed User
Longtime User
Story:
my app has the possibility for 3 languages. however i have to restart the app to the language effect on the menu's. As seen on the forum "restart" is not possible.
I do following:
choose language and exit app

what i do in code:
B4X:
    SQL.Close
    DoEvents
    Activity.Finish

than i click on the icon of the app (to start) and get following (image did not upload):
"An error has occurred in sub:
Java.lang.illegalStateExeption: attempt to re-open
an already-closed object: SQLitedatabas: /path of file/database.db
continue?"

if i say YES then same error is shown
if i say no AND re-click the app ICON, than app starts with no problems.

Now my questions:
1) do i click to quick to restart my app?
2) is there a way to wait until SQL.Close is really closed?
3) and last: is there an other way or A way to restart app?

one other question came to my mind: do i have to open the database.db in every activity
or only ones in the main (did not test this yet)?

long story but thanks to anyone who wants to reply.

as an addition I just discovered it's not only the change language but also close and start app. after this more code to show
B4X:
DBUtils.CopyDBFromAssets("database.db")
and
B4X:
If FirstTime Then
        SQL.Initialize(File.DirDefaultExternal, "database.db", True)
End If


Regards, Léone
 
Last edited:

Diabolus

Member
Licensed User
Longtime User
If you close the database you need to initialize it and therefore remove If FirstTime Then.

You don't need to open database in every activity, only in main.
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
thanks Diabolus,

i tried your last suggestion but i get an error if i don't do so.
in every module i have to initialize otherwise i get an error. That i don't have to copy i know. so what is wrong if i wouldn't have to do?
i have the above code in every module (activity) having 6 is that 6 times in app.

for the other error i found ExitApplication instead of activity.finish
 
Upvote 0

Diabolus

Member
Licensed User
Longtime User
B4X:
Main Activity

Sub Process_Globals
Dim SQL As SQL
End Sub

- - -

Another Activity

Main.SQL.ExecQuery(...
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
OK! now i understood your suggestion above. you are referring back to main.
Thanks, nice way to do this. i will use this.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…