Hello guys (and girls),
I need your help in the matter of how to structure things in an Android app that I'm developing.
So far I have:
- a Login activity that shows up right after the app is started
- a Main activity that display some options for the user. Among them there is an option to start the device's camera (user taps on an icon that should launch the Camera), take a picture, crop it / rotate it and upload it to a remote server
Now, my question is: how should I organize things in my app logic so that everything will be clear and easy to manage in the future, for the upcoming versions?
I'm thinking like this but I'm not sure if it is the right way:
- create a separate activity (eg. PictureCaptureActivity) for the picture capture task
- create a separate activity (eg. PictureProcessActivity) for the picture processing tasks (crop and / or rotate - these options will be available via some buttons displayed on screen, in the main menu bar)
- create a separate activity (eg. PictureUploadActivity) for the picture upload tasks
Or should I include all these functionality in my MainActivity somehow? Or... ?
Thank you in advance for your guidelines!
3 Answers 3
PictureCaptureActivity
Do you want to have a custom interface for taking pictures with the camera, or use an existing application on the phone?
Yes - You will need a PictureCaptureActivity and will have to implement the camera functionality yourself.
No - You can use an Intent to get the user to take a picture using another application and return it to you.
Either way, you will need to look at the Camera documentation.
PictureProcessActivity
You will most likely need to have a PictureProcessActivity to process the pictures in the manner you want.
PictureUploadActivity
The PictureUploadActivity is not really necessary. You could use a Progress Dialog or Progress Bar to show the progress in the PictureProcessActivity.
MainActivity
In my opinion you need at least two activities:
MainActivity/PictureCaptureActivityto take a photoPictureProcessActivityto process the photo
You could fit it all into one activity by hiding and showing icons in the Action Bar, but I'd rather not because the Activity Documentation states:
An activity is a single, focused thing that the user can do.
Disclaimer: There is no 100% correct way to do this.
2 Comments
Before i start referring you to well written documentation and examples i have one main point i would like to emphasis and convey.
You are referring to Activities where modern Android applications are compartmentalized by Fragments (not that modern, almost 3 years) and the point of that being that the same application can work by utilizing almost 100% of the code on all Android* devices and form factors (mobile, tablet, TV, wear, auto etc.).
Now lets talk business, the best place to start reading on regarding Android is Google:
- Design/patterns/application structure - from the android.developers.com documentation site.
- Application quality checklist - created by Google following hundreds of case studies and a meticulously planned UX test.
- Design guidelines - updated just 2 days ago (16.4.15).
- IOSched - Google's display window for Android code where they show how they think an Application should look, feel and behave.
After that i would love to link you to a code lab i co-wrote with a couple of friends and a few blog posts i have written as a follow-up:
Goodluck.
2 Comments
I've found this to be very helpful when it comes to code keeping: https://google-styleguide.googlecode.com/svn/trunk/javaguide.html
The one thing I can't stress enough: comment your code