Design of Android app to use web api
I'm starting an Android app which will have multiple Activities. It will be using a REST api with OAuth. I have tested the OAuth and have successfully parsed the returned xml.
My question has to do with the architecture of designing a client like this. I have a HttpClient and OAuthConsumer objects which will be used from the v开发者_Python百科arious Activities. I started designing a DaoFactory pattern which would provide DAOs for the various API calls. But I don't know how to make this pattern work in the Android framework. Each Activity can come and go and the user moves through the screens. Where should I store these objects? Should I make them members of the Application class and access them with getApplication()? Should I put the network calls and xml parsing code in a Service for each of the Activities to use?
I guess I'm trying to make this like a 3 tier webapp, but was looking for examples of other rich Android clients. I appreciate any help or advice.
It depends on the details of your app of course. If the network calls can continue in the background, independently from any visible activity, then you probably want to put them in a Service, and have each interested Activity bind to the service.
BTW applying patterns commonly used in enterprise Java to Android is not always a good idea: see Designing for Performance.
精彩评论