View Source

h2. Download

Get the [2.0.0-beta release here.|http://packages.couchbase.com/releases/mobile/android/android-2.0.0-beta/android-couchbase-2.0.0-beta.zip]


h3. {color:#a30a0a}Getting Started{color}

{color:#5b5352}We're just gonna jump right in here and talk how-to. These instructions require you to have {color}[installed Eclipse and the Android SDK, via these instructions or similar.|http://developer.android.com/sdk/installing.html]{color:#5b5352} Once you have that, you can do this:{color}
# {color:#5b5352}Create a new Android project or select an existing project{color}
# {color:#5b5352}Copy the Couchbase.zip and couchbase.xml files into the top-level of the project:{color}
# {color:#5b5352}Right-click on couchbase.xml and select Run As > Ant Build (or select it and click the green Run arrow).{color}
# {color:#5b5352}Refresh your project{color}

h3. {color:#a30a0a}Your App Code{color}

{color:#5b5352}Now that your project supports Couchbase, starting Couchbase is accomplished by adding a few things to your application's Main Activity.{color}

{color:#5b5352}1. Create an instance of ICouchbaseDelegate, you can implement these methods to respond to Couchbase events:{color}
{color:#5b5352} {color}
  {color:#000000}{*}private{*}{color}{color:#222222} {color}{color:#000000}{*}final{*}{color}{color:#222222} ICouchbaseDelegate couchCallbackHandler {color}{color:#339933}={color}{color:#222222} {color}{color:#000000}{*}new{*}{color}{color:#222222}ICouchbaseDelegate{color}{color:#009900}({color}{color:#009900}){color}{color:#222222} {color}{color:#009900}{{color}

{color:#222222}      @Override{color}
{color:#222222}     {color} {color:#000000}{*}public{*}{color}{color:#222222} {color}{color:#000066}{*}void{*}{color}{color:#222222} couchbaseStarted{color}{color:#009900}({color}[String|http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky]{color:#222222} host, {color}{color:#000066}{*}int{*}{color}{color:#222222} port{color}{color:#009900}){color}{color:#222222} {color}{color:#009900}{{color}}{color:}   {color}

{color:}      @Override{color}
{color:#222222}     {color} {color:#000000}{*}public{*}{color}{color:#222222} {color}{color:#000066}{*}void{*}{color}{color:#222222} exit{color}{color:#009900}({color}[String|http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky]{color:#222222} error{color}{color:#009900}){color}{color:#222222} {color}{color:#009900}{{color}}

   }


{color:#5b5352} {color}
{color:#5b5352}2. Declare a ServiceConnection instance to keep a reference to the Couchbase service:{color}
{color:#5b5352} {color}
{color:#222222}    {color}{color:#000000}{*}private{*}{color}{color:#222222} ServiceConnection couchServiceConnection{color}{color:#339933};{color}
{color:#5b5352} {color}
{color:#5b5352}3.  Add a method to start Couchbase:{color}
{color:#5b5352} {color}
{color:#222222}   {color} {color:#000000}{*}public{*}{color}{color:#222222} {color}{color:#000066}{*}void{*}{color}{color:#222222} startCouchbase{color}{color:#009900}({color}{color:#009900}){color}{color:#222222} {color}{color:#009900}{{color}
{color:#222222}        CouchbaseMobile couch {color}{color:#339933}={color}{color:#222222} {color}{color:#000000}{*}new{*}{color}{color:#222222}CouchbaseMobile{color}{color:#009900}({color}{color:#222222}getBaseContext{color}{color:#009900}({color}{color:#009900}){color}{color:#222222}, couchCallbackHandler{color}{color:#009900}){color}{color:#339933};{color}
{color:#222222}        couchServiceConnection {color}{color:#339933}={color}{color:#222222} couch.{color}{color:#006633}startCouchbase{color}{color:#009900}({color}{color:#009900}){color}{color:#339933};{color}
{color:#222222}   {color} }{color:} {color}
{color:#5b5352} {color}
{color:#5b5352}4.  Call the startCouchbase method from the appropriate Activity lifecycle methods.  For many applications the onCreate method is appropriate:{color}
{color:#5b5352} {color}
{color:#222222}    {color}{color:#000000}{*}public{*}{color}{color:#222222} {color}{color:#000066}{*}void{*}{color}{color:#222222} onCreate{color}{color:#009900}({color}{color:#222222}Bundle savedInstanceState{color}{color:#009900}){color}{color:#222222} {color}{color:#009900}{{color}
{color:#222222}        {color}{color:#000000}{*}super{*}{color}{color:#222222}.{color}{color:#006633}onCreate{color}{color:#009900}({color}{color:#222222}savedInstanceState{color}{color:#009900}){color}{color:#339933};{color}
{color:#222222}        ...{color}
{color:#222222}        {color}{color:#006633}startCouchbase{color}{color:#009900}({color}{color:#009900}){color}{color:#339933};{color}
{color:#222222}   {color} }

{color:}Once Couchbase has started you will get a notification by your delegate callback being called with couchbaseStarted. At that point you have can construct a server and database URLs, and proceed by using high-level libraries like Ektorp.{color}
{color:#5b5352} {color}

h2. {color:#004768}Client Library{color}

* [We recommend Ektorp|http://ektorp.org/]

h2. {color:#004768}Example Applications{color}

* [GrocerySync|https://github.com/couchbaselabs/AndroidGrocerySync]

h2. {color:#004768}Documentation{color}

* [Couchbase HTTP API|http://docs.couchbase.org/couchbase-api/index.html]

h2. {color:#004768}Join the Community{color}

* [Community Mailing List|https://groups.google.com/forum/#!forum/mobile-couchbase]
* [Web Forums\|/forums/couchbase/mobile|]
* [Report Bugs\|/issues/browse/CBMA|]