New to Android and Java (not to OOP (prev C++))
I have in mind by one of the various suggested means (static application member, singleton etc) to provide access to a global SQLiteDatabase and to use SQLiteOpenHelper to open / create / access cached.
My question is actually about closing the db. I think have seen almost as many opinions on this as there are people and each seems very certain of their view.
I think some are recommending close each time you move away from an activity. Does one do this for safety of data or for saving memory or because its the only place to do it. If one does this there seem to be different opinions where you do it. Some say you must close the db in onDestroy. However as far as I can see if you go to another view the first view may not have its onDestroy called til later (when the system needs more space) and then the db may be closed while the 2nd view is performing some action on it.
The alternative I see is to only close the db when the application is finished with but I cannot see a completely certain way to do this.
The fact that (it seems to me) so many people are so firm about conflicting opinions suggests this area of the API is either poorly designed or poorly documented.
On the other hand I may have completely misunderstood the whole thing. Any clarification would be greatly appreciated.
I have in mind by one of the various suggested means (static application member, singleton etc) to provide access to a global SQLiteDatabase and to use SQLiteOpenHelper to open / create / access cached.
My question is actually about closing the db. I think have seen almost as many opinions on this as there are people and each seems very certain of their view.
I think some are recommending close each time you move away from an activity. Does one do this for safety of data or for saving memory or because its the only place to do it. If one does this there seem to be different opinions where you do it. Some say you must close the db in onDestroy. However as far as I can see if you go to another view the first view may not have its onDestroy called til later (when the system needs more space) and then the db may be closed while the 2nd view is performing some action on it.
The alternative I see is to only close the db when the application is finished with but I cannot see a completely certain way to do this.
The fact that (it seems to me) so many people are so firm about conflicting opinions suggests this area of the API is either poorly designed or poorly documented.
On the other hand I may have completely misunderstood the whole thing. Any clarification would be greatly appreciated.