Onyx Database with Android

Android NoSQL Database
Integrate Onyx Database with Android
This tutorial will guide you through how to integrate Onyx Database within an Android project. Create a database within Android and use it within a mobile application.

The example application illustrates how to create an Android application with an in-memory database. The Android application is a simple master detail application for displaying cookbook recipes. It contains the entire Gradle configuration and dependencies. It contains an example on using Java 8 with Android using Jack Options and an example of how to use Onyx Database to retrieve application data.

You can download the code for this example here: OnyxDevTools/onyx-database-samples/onyx-android-example.

Configure using Gradle

  1. Define the gradle build file to use jackOptions
    Jack Options is required since Onyx Database uses lambda expressions.
    Jack Options will soon be deprecated. When that happens, this step will not be needed.
    Alternatively to using Jack Options you can use Retrolambda. Both are compatible.
    This example uses the latest build tools 25. We recommend using build tools 25.
    Source target and comparability are set to Java 1.8.
  2. Add Onyx as a maven dependency.

    Add maven central as a dependency source and add the latest Onyx as a dependency.

    The onyx-android dependency is all you need to get started.
    When android officially supports Java 8, you can switch to use the onyx-database module as a dependency rather than onyx-android.

Start Using Onyx NoSQL

  1. Define an entity
  2. Create a Persistence Manager Factory

    In this example we are using an cache in memory database. Alternatively you can connect to a remote or embedded database instance.

    If you are connecting to a remote database you must include permissions within the AndroidManifest.xml
    Android requires network communication to occur on a background thread. If you are using a remote database, execute the Persistence Manager and Persistence Manager Factory API within a background thread.
  3. Save an entity

    Upon executing your application, Onyx has automatically created an embedded database. This is a simple example on how to get started with Android. Other tutorials also contain information that apply to building out graph data models and interacting with the Persistence Manager API.

  4. Spring Configuration