开发者

Design of Android app to use web api

开发者 https://www.devze.com 2022-12-15 16:48 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消