Android Question SQL.close

yiankos1

Active Member
Licensed User
Hello team.
I initialize sqlite at starter service. Everything works fine. Where should we call SQL.close? Because i call sql.close at Main activity_pause if user closed and throws me an error if i close app and reopen imediately. Error is about: reopen a closed database.
Thank you for your time.
 

yiankos1

Active Member
Licensed User
Thank you for your answer. But SQL is initialized from starter service.
As i see at log, odd times entry point is Starter service(does not crash), even times entry point is main activity and after that starts starter service(app crashes because SQL is not initiliazed).
Is there any bug with starter service?

p.s. b4a is latest version
 

KMatle

Expert
Licensed User
No. There is no bug but the starter service is just to start some things. I prefer not to use it. Use another service than the starter service. E.g. I have several services for db handling, encryption, communication, etc.

So start and stop the - let's call it "db service" by your own code. Then you have no side effects and all under control.

Closing the db intentionally is a good practice. Check if it's initialized and if not reopen it.
 

Erel

Administrator
Staff member
Licensed User
As i see at log, odd times entry point is Starter service(does not crash), even times entry point is main activity and after that starts starter service(app crashes because SQL is not initiliazed).
Is there any bug with starter service?
This is unexpected assuming that you are not doing something wrong like starting the starter service yourself.

Please post the logs and if possible post a project that demonstrates it.

There is no bug but the starter service is just to start some things. I prefer not to use it.
I consider it a bad suggestion.

Closing the db intentionally is a good practice.
I consider it a bad suggestion as well. Especially in the general case.

Android apps are different than desktop apps. They don't have a clear or well defined closing event. You can make your app more complex than it should be by closing the database in Activity_Pause (of each activity) and then open it again. Nothing good will come out of this.
 
Top