Skip to content

Instantly share code, notes, and snippets.

@alexjlockwood
Created May 23, 2012 01:18
Show Gist options
  • Save alexjlockwood/2772709 to your computer and use it in GitHub Desktop.
Save alexjlockwood/2772709 to your computer and use it in GitHub Desktop.
Singleton Database #1
public class MainApplication extends Application {
/**
* see NotePad tutorial for an example implementation of DataDbAdapter
*/
private static DataDbAdapter mDbHelper;
/**
* Called when the application is starting, before any other
* application objects have been created. Implementations
* should be as quick as possible...
*/
@Override
public void onCreate() {
super.onCreate();
mDbHelper = new DataDbAdapter(this);
mDbHelper.open();
}
/**
* Called when the application is stopping. There are no more
* application objects running and the process will exit.
* Note: never depend on this method being called; in many
* cases an unneeded application process will simply be killed
* by the kernel without executing any application code...
*/
@Override
public void onTerminate() {
super.onTerminate();
mDbHelper.close();
mDbHelper = null;
}
public static DataDbAdapter getDatabaseHelper() {
return mDbHelper;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment