1

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!

asked Apr 16, 2015 at 16:08

3 Answers 3

1

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:

  1. MainActivity / PictureCaptureActivity to take a photo
  2. PictureProcessActivity to 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.

answered Apr 16, 2015 at 16:40
Sign up to request clarification or add additional context in comments.

2 Comments

No, I don't need a custom interface for the picture capturing process - I'll just rely on the default interface of the user's device (there is no need to reinvent the wheel here). So, basically, I'll have two activities: MainActivity (that will take care of camera launch, among other things) and PictureProcessActivity (that will take care of picture crop and / or rotate and, also, will trigger the picture upload process), right? Any thoughts on if I should integrate the Fragments idea here?
Yes, that is correct. @royiby rightly suggested the use of fragments for reusability across multiple devices and form factors. See the Fragment Documentation for more: developer.android.com/guide/components/fragments.html
1

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:

  1. Design/patterns/application structure - from the android.developers.com documentation site.
  2. Application quality checklist - created by Google following hundreds of case studies and a meticulously planned UX test.
  3. Design guidelines - updated just 2 days ago (16.4.15).
  4. 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:

  1. AndConLab
  2. My tech blog on Android

Goodluck.

answered Apr 16, 2015 at 16:37

2 Comments

Thank you for your time spent on writing your answer! Those are some quite good resources and I'll check them for sure. At a first glance, I conclude that Fragments are the right way to solve my logic issue...
My pleasure, feel free to accept my answer at any time :)
0

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

answered Apr 16, 2015 at 16:20

1 Comment

Thank you for your thoughts! I'm well familiar with the best practices in programming as I have a long background as a PHP developer... and, no matter the language, the best practices guidelines are almost the same, no matter the language used :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.