You can achieve it extending the Application class. Google has this to say about it:
Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, which will cause that class to be instantiated for you when the process for your application/package is created.
There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.
I have done it myself like this:
public class App extends Application { private DbHelper dbHelper; @Override public void onCreate() { super.onCreate(); dbHelper = new DbHelper(this); } public SQLiteDatabase getDatabase(){ return dbHelper.getWritableDatabase(); } @Override public void onTerminate() { super.onTerminate(); dbHelper.close(); } }
Then you just access it calling getApplicationContext.getDatabase()