Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design patterns for Android [closed]

I'm working in a new app for Android. Since it is my first time working with it, I don't know how structure it. I'm searching for a nice design pattern to use.

My application will make connections with a WebService and also, will save some information in local.

Which design patterns will be nice for my app?

I saw MVP pattern (Model-view-presenter) but I read it is focused to do tests.

like image 681
FrioneL Avatar asked Nov 05 '22 13:11

FrioneL


1 Answers

WebService interface

Basically you have two main routes to achieve a WebService interface.

  • You can use the WebApps way. It is a WebView centered approach, in this way it is more remote-driven: you can upgrade the website css/html and make large changes to the layout and content without requiring your users to upgrade your app on the market.

  • You can also use the WebWorkers way. It is application/android centered. You use Asynchronous threads to fetch data from the website, on success, they call a Handler in your UI which is responsible for displaying it using a WebView or android widgets (ListViews for example). This is longer to code and (hence) more error prone but you can achieve a much better android integration (using Notifications, background checking, ListView based activities).

Information persistence

This really depends on how much information you want to store and how much you want it to be shareable the android way.

  • The best (and harder) android integration is achieved with a full-blown ContentProvider whose backend storing is delegated to sqlite. API Demos have nice code samples for this.

  • For a fixed number of data persistence, SharedPreferences is much simpler.

  • This article is a good tutorial on android data persistence.

MVP design

MVP is used throughout android framework, this is not a choice really, you have to comply with it whenever you want to use standard widgets ;)

like image 148
Laurent' Avatar answered Nov 15 '22 06:11

Laurent'