Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

My First TouchDB Replication

mschoch edited this page · 13 revisions

This guide will help you get started with TouchDB-Android and perform your first replication.

  1. Add the TouchDB Projects to your Eclipse workspace (as described here Building-TouchDB-Android)
  2. Create a new Android Project (targeting Android SDK 2.2 or newer)
  3. Add the Android Library references to TouchDB-Android and TouchDB-Android-Ektorp
  4. Add the following static initializer block to the Application's main activity:
  {
      TDURLStreamHandlerFactory.registerSelfIgnoreError();
  }
  1. Add the following code to the onCreate() method of the Application's main activity:
      // start TouchDB
      TDServer server = null;
      String filesDir = getFilesDir().getAbsolutePath();
      try {
        server = new TDServer(filesDir);
      } catch (IOException e) {
        Log.e(TAG, "Error starting TDServer", e);
      }

      // start TouchDB-Ektorp adapter
      HttpClient httpClient = new TouchDBHttpClient(server);
      CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

      // create a local database
      CouchDbConnector dbConnector = dbInstance.createConnector("testdb", true);

      // pull this database to the test replication server
      ReplicationCommand pullCommand = new ReplicationCommand.Builder()
          .source("https://example.iriscouch.com/example_db")
          .target("testdb")
          .continuous(true)
          .build();

      ReplicationStatus status = dbInstance.replicate(pullCommand);
Something went wrong with that request. Please try again.