Problem with app being sent to the Background

Ever since iOS 13 my app has had problems if it is sent to the background and then brought back to the foreground. I have eventually tracked it down and it looks as though iOS closes all open databases if you send it to the background. Has anyone else found this and designed a work around ?

I should add that simply opening the SQL database again is not a solution, it causes consequential errors further down the line, For example, in the following code segment:

       sqlList[0]=["SELECT * FROM groups ORDER BY key;", groupchangetwoHandler]
       Sql(DB, sqlList)  
 End Function

 Function groupchangetwoHandler(transaction, results)
      GroupRecords = results.

The first console.log call correctly displays the variable CurrentCode as “2”, but the second one displays it as “1”. I just don’t know enough about what happens inside the Sql(DB, sqlList) call that can make a independent global variable change value.

Any thoughts ?

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly. (We fixed it for you this time)

How does CurrentCode get set? It’s not manipulated directly by AppStudo.

What about your other global variables? Are the preserved after returning from background?

It’s just a normal Global variable that tell the app which screen the user is looking at. Haven’t managed to get the app running after being brought to the foreground so have no idea if other variables are preserved or not.

That might be useful to investigate.

I’ve a couple more occasions where the SQL call is changing the value of a Global variable that has nothing to do with the call itself. Something is definitely happening when you send the app to the background.

I think I may have give this up now. Because it only happens running under iOS I cannot debug it on the PC so I am having to deploy each test run to my server and run it from there. And because iOS does not report any error but just stops working I am having to resort to using MsgBox to check on variable states. And because you now cannot use multiple Msgboxes any more (it used to be modal) then the debugging process it taking hours when It used to take minutes.

There’s a new utility which lets you debug iOS devices from Windows. Check out

Nice looking debugger. Doesn’t help me unfortunately as if I put the app to the background and then bring it to the foreground no error message is displayed. I guess closing the database is not regarded as an error.

In the end just re-opening the database resets so many other variables and pointers it is impossible to make it work.

I’ve wasted too much time on this now, I am just going to have to learn to live with it. Unless someone can ask Apple for iOS 15 not to close SQL databases if a web app is sent to the background.

Cheers, thanks anyway


It could also be that Safari is restarting the app completely when bringing back from background, which will reset all your variables.

I don’t think, so as there is no sign of the screen refreshing which would happen on a restart. Might still be clearing all the variables in the background though.