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!
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:
AndConLab
My tech blog on Android
Goodluck.
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 / PictureCaptureActivity to take a photo
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.
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
Related
I have an Audio analyzer app that was exported from processing.org to Android.
It works, but it's not organized properly to extend its functionalities. Therefore, I'd like to start coding proper Android app with activities and everything needed from scratch and include existing code where needed.
But I have a problem, how to organize such app in proper Android way.
Quick description of app :
- app captures sound from microphone in frames and calculates magnitude spectrum of the frame
- app supports 3 possible graphs (time-domain, spectrum and spectrogram)
- app has 4 screens - fist screen displays all 3 smaller graphs and then user can touch each graph to get into separate screen with bigger screen
I get that those screens are probably separate activities under Android (4 of them), but I'm not sure how to use audio capture and analysis code that is basically active in background and serves data to be displayed to all activities ?
If you can give me an advice or pointer to some similar examples where I can learn about it.
Thanks in advance,
regards,
Rob.
Hello)I suppose that the best practice to organize such structure will be one activity and fragments inside of them.
For instance: one FragmentActivity hosts your fragments and displays them together. When you press on your layouts with fragments - you go for details to another fullscreen fragment.
To use background process you have to implement services - just like in any music app. About communication of services with activities you can real below:
https://developer.android.com/guide/components/services.html
Here you can read about fragments:
https://developer.android.com/guide/components/fragments.html
I am thinking about creating a text-based game (similar to gamebooks) for android device. In this moment only theoretically. Do you have some advice please, which way to go?
You probably know how gamebooks works, but the gamebook I want, will be very easy, should work like this:
User has shown some image, text and 3 options (questions), he decides which option to click, then a new page is showing (according to the clicked option) with another image, text and another 3 options. Then again, the user clicks one option, another page opens, etc.
My question is not how to do it programmatically, but how to start with this in Android Studio, what system to use for such game on android or which way to go.
Because I think it has no sense to create intents after each click, as there might be hundreds of clickable options.
I have already created such game on my website with php/html/js, but I want to create it also offline for android.
Intents implies one activity per page - unmaintainable.
You should work with a database and load based on user interaction. So you'll need to learn about Databases and Asynchronicity (working in the background while updating the UI so the user knows)
I have a scenario which I think is pretty common in Android applications. I know partial attempts of solving the issue were made, but until now I have not stumbled upon the full implementation. I intend to try to implement such component and open source it afterwards, but I need your help in its design.
So basically my case is the following: I have list view showing image loaded from the web and text per each row. I want to lazily load the images, placing default for each image and substituting it with the real one only when the image is downloaded. I also want to keep image cache avoiding the need to download the images multiple times in short period.
Up to now I have found several implementations that are partially working including:
Tom van Zummeren's implementation of similar component with several well known problems
Jeremy Wadsack's refinement of the concept, which is more or less working
Lazy drawables source forge project.
I also saw several stackoverflow questions regarding the problem: 1, 2, 3
However I have one more requirement which makes my task a bit more complex: I allow the user of my application to affiliate himself with some of the images. I want to load the new images associated to the user whenever the user navigates to the home screen. From it he should be able to go see his images, even before they have all been downloaded and in this case again default placeholders should be visible (Note the cross screen transition). Such use cases are:
An app listing user's youtube videos
An app for facebook - consider the images of friends
An app serving news that supports user's favorites etc
Note that I want to start fetching the new data related to the user on the home screen to provide better user experience. I will keep the user-related data stored locally forever.
The question
So my basic question is what approach should I use for the implementation of the image downloading? I know that the Android manuals say Service should be used only when I want to execute task even when application is not running. On the other side I will start the image downloading on the home screen and link the downloads to UI elements just when the user navigates to the new screen (Activity) - user-related list view and I do not know how to achieve that with AsyncTask (not that I have a very precise idea how to do it with Service either).
Any suggestion will be greatly appreciated, including links.
Universal Image Downloader is a good library which helps you to do image downloading in background with your settings.
It has so many features that you can implement at your own way.
I am new to Android. So new that I am not even clear on the terminology. From the user perspective, one can swipe from one page (iOS term) to another on Android. I have been told that these are called "panels" - but googling that term, I find out about the notification panel - which seems to be what iOS would call the status bar. Or, perhaps, these are called "home screens"
I would like to find out if there is a way to change the background image as the user swipe from one page/panel(?) to another. For example, I might want my game apps to have a green background and my social media apps to have a blue background. If this can be done by setting a panel's background image, that would be good. If there's a hack with wallpapers, that would be okay, too.
Any pointers to Android UI guideline doc that names visual entities would be great. Likewise, any pointers to a glossary of Android UI terms would also be wonderful.
Thanks in advance.
UPDATE:
I have just come across "live wallpaper" and am wondering if this - with onOffsetsChanged() - is the way to go.
In regards to the widget questions the term has two meanings: the UI components provided by the API such as TextView, Button, and WebView and the other meaning is an icon on the launcher that does more than start an app. The latter is also referred to as App Widget and an example of this would be music player controls or weather report. Both kinds of widgets are documented at the Android Developer website.
Wallpapers are typically Live or static. Live Wallpapers are similar in idea to screensavers but do not have the same function as screensavers are for inactivity. They can also be interactive. Static wallpapers are generally bitmaps that are cropped for the situation or specially made for the dimensions. In addition a Launcher (which is the name of the "desktop application" and the Launcher Home being the "Desktop") can be replaced to provide additional features for wallpapers. For your specific question about having an image gallery style wallpaper, the vanilla Launcher does not support this.
I'm working on android application that will have basic image gallery functionality included. I've managed to build activity that fetches list of photos from my application backend API and render them in android gridview within activity layout.
This is how it looks like at the moment:
However I'm having difficulties to build same gallery experience for user's device photos that were taken by camera and stored on device. Two solutions I considered were:
Building my own image gallery.
Starting default android image gallery using intent.
Solution 1: I belive that first solution will take me too much time to developed. I started with this tutorial but as soon I implemented it I found out that it is running too slow. Then I take a look at android camera source code to find solution but again I found that it will take me too much time to review the code and to build my own gallery from scratch. I also believe that it is not in Android OS philosophy to rewrite functionalities that already exists but to use Intents to start activities that can handle actions you need. This lead me to second solution.
Solution 2: I tried calling default android gallery using intent in order to browse user's device photos by soon I was stuck again. Problem this time was that as soon as user tap on photo, gallery exits and returns to activity that originaly started it, and I expected (and I want) to start large image preview instead. I saw that others had this problem too how to open gallery via intent without result.
Because I didn't find the fix for this I decided to quit.
My question is how can I overcome these problems and build gallery that is similar to one I already have for web photos.
If anyone could give me reference I would be most thankful.
this question is pretty old but, as it has a lot of views and quite a lot of upvotes, it could be good to bring an answer to it.
So, first the tutorials evolved a bit and you can find some cool stuff for your #1 option:
This is the one I prefer
This one uses a deprecated UI element but is also cool
This uses an Adapter which is, to me, the best way to proceed.
For your #2 option, I do not see any idea to not to return to the original activity because you still do not have control over the result of the intent you send through the system.
But there are another solution that you didn't mention: there are librairies which are very cool and that you could customise to get exactly what you want:
This one is a bit fancy
This one seems also to be pretty cool but you could have problems importing it because it's not a gradle project
This is the one I would definitely use.