01Aug

Installation

How to include DataDroid in your project ?

The project code is hosted on GitHub.
This project is however now deprecated.

Once you have downloaded the project from GitHub, you need to add the DataDroid project (located in the DataDroid/ subfolder) in your workspace like a normal Android project.

Then you have to add the DataDroid Android Library to your project. If you don’t know how to do that, you can find informations about this here.

How to write the code for your first webservice ?

Now that the DataDroid library is included in your project, let’s see how to write the code for your first webservice:

  1. To begin, you need to create a subclass for RequestManager and RequestService.
    You can use the skeleton classes provided in the skeleton package of the sample project to start.
  2. You need to add your subclass of RequestService in your manifest as a service.
    1
    2
    3
    
                <service
                    android:name=".data.service.MyRequestService"
                    android:exported="false" />
  3. You need to then create your Request object and the corresponding Operation implementation.
    Check PoCRequestFactory and CityListOperation/PersonListOperation in the sample project for examples.
  4. Now that this is done, you need to link your Request and your Operation by implementing the getOperationForType() method in your RequestService subclass.
  5. To finish, you need to execute the request in your Activity with a RequestListener
    Check CityListActivity/PersonListActivity in the sample project for examples.

How to migrate from v1 to v2 ?

So you currently have a project using DataDroid v1 and you want to use the new version 2. Let’s see what there is to do to migrate :

  1. Let’s start with the Service:
    • Open your Service class and remove pretty much everything. Modify the class to extend RequestService.
    • If you were specifying a number of threads different than 1, override the method getMaximumNumberOfThreads().
    • Override the method getOperationForRequestType() and leave it empty for now.
  2. Let’s migrate the RequestManager:
    • In your RequestManager subclass, copy somewhere else all the code corresponding to your requests and remove everything else except the singleton management.
    • You know just need to add a constructor taking a Context and giving it to its parent class as well as the name of your RequestService subclass.
      Check PoCRequestManager to see what you should have at the end
  3. Now we need to migrate the webservice code itself:
    • Change your Worker classes to implement the Operation interface and do the appropriate modifications in the class to follow the interface protocol.
    • Use the code you save earlier from your old RequestManager to create the Request object corresponding to the Operation.
      You can use the same pattern I chose: Have a RequestFactory class to create all the Requests in only one place.
    • Make the bidding between the Request and the Operation by modifying the getOperationFromRequestType() method in your RequestService subclass.
  4. The last step is to modify the code starting your requests and managing the results.
    • You need to change your listener from the old OnRequestFinishedListener to the new RequestListener. Once again, most of the boilerplate is now done for you so you only have to write your own logic in the listener callbacks.
    • Change the listeners and requests management in your Activity lifecycle. Check CityListActivity or PersonListActivity to see how to do it.

If you want to have some information about the benefits and the costs of migrating from v1 to v2, you can check this article.

2 Responses to “Installation”

  1. [...] use the DataDroid library for my Android application project. My project is written in Scala. The DataDroid instructions [...]