You are here: Platform Specific Issues > Android > Getting Started

Getting Started

It takes only a few steps to get started with db4o and Android. This description assumes that your using Eclipse to create your Android application.

Setup db4o for a Android project

  1. First download the Java version of db4o at the download area
  2. Unpack the distribution. Then copy the db4o-xxx-java5.jar the db4o-distribution to your Android project-folder.
  3. Add the db4o-jar to the class path. In Eclipse you do it this way. Refresh you project. Right click on the db4o-xxx-java5.jar . Choose 'Build Path' -> 'Add to Build Path'
  4. Your done! You can now use db4o in your Android application and it will be deployed automatically when running the Android emulator.

Using db4o in a Android application

You can use db4o on Android as normally. However you when you create a db4o-database you should use a file in the application-context. The start class of your application itself is usually the context.

Also add the AndroidSupport to your configuration, which tunes some configuration settings to work better with Android.

public  class Db4oOnAndroidExample  extends Activity  {	
    /** Called when the activity is first created. */
    @Override
    public  void onCreate(Bundle savedInstanceState) {
		String filePath = this.getFilesDir() + "/android.db4o";
        final EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
        config.common().add(new AndroidSupport());
        ObjectContainer db = Db4oEmbedded.openFile(config,filePath);
		// do your stuff
		db.close();
    	
    }
}
Db4oOnAndroidExample.java: open db4o on Android