The idea is to use just one connection all over the APP, since it’ll be used almost everytime.
Is it possible to get the SQLiteDatabase and turn it to a global variable to be used all over the app?
Which way should i follow to make this?
Thx in advance.
The two current answers say the same thing, and they are 100% right, but maybe don’t explain the whole thing.
In the android framework, the Application class is where you would put any variables and data you want globally accessible.
http://developer.android.com/reference/android/app/Application.html
From any activity you can call getApplication() and it will return the application instance you created.
So then you can make the database available by adding a public method to your application.
In the end you’d do something like:
Then in your Application class you would fill out the getDatabase() method.
A slightly better approach might be to create a class that manages the database, and make that class a member of the application. This would let you encapsulate all the open cloase and business with the database in one class. Then you could use methods of the application class to pass back Cursors from queries, etc.