I still need to watch this talk... when i get some time :-) Right now i'm working on a project for my job that involves a REST-ful client on Android and a REST server.
I have not implemented the REST-communication on the client using a ContentProvider and Service. I did do that a good year ago with another project (Smugmug REST) and it's elegant, but I found that it is not really necessary. In my current project, I've implemented the REST-communication using AsyncTask and the 'Restlet for Android' library. The AsyncTask holds on to an application-context (not the context of an activity, since that could introduce memory leaks) and keeps track of pending REST- requests in an object passed around by through 'last-configuration- instance'. By not using a ContentProvider/Service, the callback mechanisms has been simplified a *lot*. On Jun 8, 11:35 am, Andrew Brampton <[email protected]> wrote: > I've watched many of the Google IO talks and one that I'm trying to > reproduce is "Developing Android REST client applications"[1]. In this > talk Virgil suggests you should not execute your RESTful queries > inside a Thread/AsyncTask spawned from your Activity (which I had been > doing), instead you should use a more complex architecture that uses a > combination of a ContentProvider and a Service. > > From what I understood the reason for this design was so your data was > more persistent between app restarts, and so your queries don't > disappear if your Activity starts/stops (e.g on a screen rotation). I > buy into both those reasons hence I'm trying to implement this. > > On the slides[2] page 45 We have an Activity calling a > ContentProvider. Now the ContentProvider checks its local database, if > the content is not there it sends an Intent to a service which fetches > the content, inserts it into the ContentProvider, then the > ContentProvider calls back to the Activity (with a ContentObserver) > and the Activity can carry on. The question I have is how is this > callback setup. The ContentProvider exposes simple methods, query, > insert, update, delete which don't seem easy to adapt to a callback > interface. > > It could be implemented by a Cursor which is designed to block, but > that could be problematic as you don't' want to block your UI Thread. > I'd appreciate if anyone could make this clearer to me, or show me > some code. I'm hoping the Twitter app will be open sourced soon which > apparently uses this architecture. > > thanks > Andrew > > [1]http://code.google.com/events/io/2010/sessions/developing-RESTful-and... > [2]http://dl.google.com/googleio/2010/android-developing-RESTful-android... -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

