Design of Android app to use web api

偶尔善良 提交于 2021-01-29 11:43:29

问题


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 various 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.


回答1:


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.



来源:https://stackoverflow.com/questions/1983329/design-of-android-app-to-use-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!