Wednesday 15 June 2011

Using Android with PureMVC and OrmLite

There are very limited examples or tutorial about how to integrate PureMVC as a framework in your android application in the web. You will also find some more examples about how should you incorporate ORMLite as a ORM system in your application.

But , if you want to use both in your application to make it more structured and concrete , well... then you are in trouble , cause there is no such example code or tutorial available so far in the internet.

After spending a lot of time in it , atlast I able to integrate all of them , which is Android-PureMVC-ORMLite successfully.

Please find the sample project where I have implemented Android , PureMVC as well as ORMLite.
I am assuming people whoever reading this post have clear knowledge in all of them (Android,PureMVC, ORMLite).

Please download the sample code from here.

If you are not then please refer to ,
http://developer.android.com/index.html for Android
http://puremvc.org/content/view/98/189/ for PueMVC
http://ormlite.com/sqlite_java_android_orm.shtml for OrmLit

Setup Sample App : Please download the app and import this as Android Project into your workspace.
There are some external jars which needs to be added to the Project's build path. So, please do that before compiling the project.

Goal of the Sample App : This a very simple app with 2-3 screens. People can login into system or sign up ( in case they don't have a user ) in it.
On successful signup/login , there will be a welcome screen shown.
That's it !!!

App flow : According to PureMVC , proxy should have all the data connection and database transaction. In this app, there is a single proxies which is MemberProxy (com.cz.sample.member.model..MemberProxy). So, we need to include the ORMLite in the proxy itself.
According to OrmLite , there should be a Database Helper in the app and so we have here in the app( com.cz.sample.db.DatabaseHelper), which holds all the db related information i.e. database name , table name etc.

So, to incorporate ORMLite into PureMVC , we have to create an instance of DBHelper in the MemberProxy and do the needful.
In the app we have only two methods which are doLogin() and doSignUp(). First one is to read the database and second one is to write. So, you will have a clear idea about both read and write.



You may email me in this a/c for further question and suggestion : surojit.pakira@collectivezen.com

Android-PureMvc-OrmLite


This app I have developed using both PureMVC and OrmLite :
https://market.android.com/details?id=com.lcs.mmp.lite

5 comments: