Separate UI from Logic in Android

1.1k Views Asked by At

I recently read a blog post by the Gmail team on the approach they used to develop the different platform versions for Inbox for Gmail. The short story is that they write everything in Java (so basically for Android) but separate all the UI code from the shared logic code. Then for iOS they reimplement the UI in a platform specific iOS manner but use a program they developed (and open sourced) called J2ObjC to convert the shared logic from Java to Objective C.

I understand how to get this working on the iOS but how should I arrange the classes on the Android? I understand that I need to create separate classes for the different parts of the shared logic but how do I this practically so that a) all the shared logic is in its own directory so I can easily reference it on it's own and b) I can still reference it from my activities.

Based on my searches I think I need to use the MVP pattern but I'm not 100% sure.

1

There are 1 best solutions below

1
On BEST ANSWER

I put the model logic in a separate project with no Android dependencies. Another project depends on the shared project and contains the user interface and builds the Android project.