This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
My First TouchDB Replication
mschoch edited this page Jul 18, 2012
·
13 revisions
This guide will help you get started with TouchDB-Android and perform your first replication.
- Add the TouchDB Projects to your Eclipse workspace (as described here Building-TouchDB-Android)
- Create a new Android Project (targeting Android SDK 2.2 or newer)
- Add the Android Library references to TouchDB-Android and TouchDB-Android-Ektorp
- Add the following static initializer block to the Application's main activity:
{
TDURLStreamHandlerFactory.registerSelfIgnoreError();
}
- 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 pushCommand = new ReplicationCommand.Builder()
.source("https://example.iriscouch.com/example_db")
.target("testdb")
.continuous(true)
.build();
ReplicationStatus status = dbInstance.replicate(pushCommand);