- Understand About MVC Pattern
MVC Stands For Model View and Controller. Each terminology is used for specific reason. There are many other pattern available like MVVM(Model View ViewModel), MVP(Model View Presenter). Where MVC is standard approach and easy to implement it.
Model : You can store your data creating model is best use for encapsulate your data from out of the world. You can access property of class through getter and setter method.
View : What you can see on the screen of mobile device through the view. View is given user experience. You can put text, image, button and many more things on View as per your requirement.
Controller : Controller is responsible for to play intermediate role between Model and View. Controller will take request from user and call network call if necessary or fetching data from DB and put it in to Model and serve this model to View. Where view can show data which user has requested.
- Explanation MVC Using Activity
In our Trip Logger Application we have used 3 Activity which is based on MVC pattern.MainActivity, SettingsActivity and MapActivity all there are associate with MVC pattern.
MainActivity : Fetching data from Trip Logger DB showing all Trip data which you had enter in past. To achieve MVC pattern, create Model and controller. Model is POJO(Plain Old Java Object) class where you can put getter and setter method. And fetching data from trip table.
Setting Activity : Setting Activity store the person’s data. His person detail can be saved in this activity. It will fetch automatically once he/she added data in DB. Setting data doesn’t have any button to save data in DB just back from the screen it will saved automatically.
Map Activity : Map Activity show Map on the screen. Showing user’s trip location on the map using latitude and longitude point of location.These location would be added when user add his trip data. Location will be added in database automatically. After successfully adding data into database user will redirect to map screen from detail page of trip detail page and click over the button called location.
- Database Schema and its Explanation
There are two table require for this application which are as follow.
- Trip data Table
- Person detail Table
Trip Data table have following column to be declare.
- ID (Primary Key, Long)
- Title (String)
- Type (String)
- Date (String)
- Destination (String)
- Comment (String)
- Image (String) // Path store in string variable for future reference.
- Latitude (String)
- Longitude (String)
Person Detail table have following column to de declare.
- ID (Primary Key, Long)
- Name (String)
- Email ID (String)
- Gender (String)
- Comment (String)
- Challenging task to complete application
There are some challenging task which i called hurdle to develop the application. Every application which is build for mobile have faced so many challenges because you need to achieve so many things in such small memory and storage.
Map Implementation : One of the toughest challenge is to implement map on the mobile device. I need to create google developer console account and get the api key to run map successfully on mobile. Also add google play service library which you provide map api to implement. Also fetch current location for that. To achieve map implementation.
Taking picture from camera : This is easy task but you need manage so many thing to complete this task because you need it’s url for future reference to show images. You have provide permission for that to open camera. Right now there is run time permission for android device.
Like trip logger application we do care lot of thing and plan before to start the application. You may need to create document and wireframe. After that you have to create flow chart diagram so you know what happen when you click on button. After that you start design for the application.
There are so many software and tool available for design the application and create prototype for you client. Such as Marvel app, Invision would help to create prototype and click event application for you client.
Hurdles during develop the application:
There are so many hurdel spawn at time of development. First how to create Design and manage architecture. Then impletementing fragment and its backstack when you click on the back button. The Fragment is part of the application and it would be difficult to manage backstack from the activity. There are two fragment in the application. When fragment open you should clear previous all the fragment and back to the activity and reload new data without refereshing the content.
Map Integration is the tuffghest part in the application because there are so many thing which you need to care before implement or integration of actual map. First you need to create API Key for the map integration you can create api key through the google account from their console part. after that you need to add library for map where you can put actual map on the view.You have to create new activity for that and display map on the screen. You require location data like latitude and longitude on the map so you need some permission for that. Once you have latitude and longitude points then you can put pin on the map so user can see where you are.
Managing database and create table for the application. This is not the tricky task but manage unique data is so important in database also save the image url in the table which you have clicked during add the trip data. To capturing images is little bit tricky part in the application because when you click and open the camera the picture which you have clicked must be save on the device and should be display when you open specific trip.