sqlite - What is the "best practice" way to keep a database reference in an Android app? -


i'm using common database of app (which consists of multiple activities , multiple fragments). imagine pretty standard, i'm asking more general question. "best" way (and why) keep track of database?

i planning on using static variable in helper class (as limited understanding of activity lifecycle means main activity can nuked later, that's not safe place leave it). option use asynctask database reference "fresh" every time need (which how i'm doing first time). don't think can send using extras , don't know of tricks make serializeable.

are there other options i'm missing? i've seen references using application, i'm not familiar those.

i planning on using static variable in helper class

that, or contentprovider wrapper around database, 2 typical approaches.

as limited understanding of activity lifecycle means main activity can nuked later, that's not safe place leave it

moreover, since have multiple activities, having database held 1 activity not useful, other activities cannot reach it.

but option use asynctask database reference "fresh" every time need (which how i'm doing first time).

that's not idea. need single instance of sqlitedatabase built-in thread synchronization work.

i don't think can send using extras , don't know of tricks make serializeable.

agreed, that's not option.

are there other options i'm missing?

as noted earlier, people use contentprovider wrapper around database. extremely useful when trying expose data third parties. there pros , cons on purely internal use.

i've seen references using application, i'm not familiar those.

since custom application subclass not gain on having singleton instance (static data member), wouldn't worry it.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -