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
Related
I have an android application working in mobile, this app has two types of activities ones that loads a list of items, and forms that open when you touch one item.
Now I have to port the app to tablet and the layouts need to be fully restructured to fit big screens, so much that the java code has to be heavily changed so i thought to merge both activities in one as shown below
Is that possible?
And if its what i need to use, fragments?
Can each activity still in its own class?(this is critical)
Can each activity have its own network operations and AsyncTasks?
Yes as you said you can use fragments for your situation (Infact their main purpose is to support different screens without code duplication). So you'll have only 1 Activity class and 2 layouts for different devices and you just need to do some run time checks and perform actions according to them.
Here you can find tutorial :- https://developer.android.com/training/basics/fragments/index.html
is not possible because only one activity working in single screen in android. i have one idea to put two fragment in single activity then use your own AsyncTasks network operation.
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
I am a novice at Android, now, I need write a android app:two screens also shows two activities, boradcast advertising on the big screen, the small screen can be operated, and they are independent of each other.When people operate the small screen, the advertising will still play. I found the presentation class in the android 4.4 API 20,with it I can realize the two screens display different contents, I also refer to the Google demo, but Because the presentation depends on the specific activity, when the small screen operated, then intent to another activity, before playing advertising presentation disappeared. Then I came up with a method: The application only have one activity, the small screen using many fragments, but because the following screen operation is very complicated, it would be more trouble with fragment, my friends advised me not to use fragment, but I can't find other methods,who can help me?thank you very much(My English is poor,sorry)
Here is a detailed tutorial of Fragment. In my opinion, you'll be able to achieve what you want, only by using fragments :
http://www.vogella.com/tutorials/AndroidFragments/article.html
Can i create a program which will cut phone screen on two parts.
Those two screen will do simultaneously two things, for example to watch a clip and to read and write sms.
I think that:
1) i need to create a home luncher application first.
How can I create a custom home-screen replacement application for Android?
2) Then i can start two fragment in my activity.
http://developer.android.com/guide/components/fragments.html
3) Finaly i open app1 in first fragment and app 2 in second fragment. Can i do that, open an application in a fragment?
Any other ideas will be usefull.
I think you need a modified version of the Android ROM to be able to do this. With the standard ROM you can only have 1 application running in foreground at any given time.
Samsung has done something similar on the Galaxy Note by allowing you to watch video while doing other things.
If you don't want to change the ROM you could implement this on your own apps, but not on all the apps.
I'm no expert, but it seems to me that you can have one application with two fragments in it. The top fragment would display video and the bottom fragment would have the messaging. Since fragments are only API 11 and up you don't have to worry about old phones being able to handle it.
Your step 3 states that you'll open apps in your fragments and I don't think that's how they work.
You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
Read more about Fragments here:
http://developer.android.com/guide/components/fragments.html
You can customize the launcher and the homescreen and lancher, check out the links below
https://android.googlesource.com/platform/packages/apps/Launcher2.git
How can I create a custom home-screen replacement application for Android?
Compile Launcher/AOSP from Eclipse:
Android Launcher application compilation on Eclipse
Read this for your information on how to compile and run your custom launcher.
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/zI9LPeU1mbc
I'm pretty much new to Android, but over the last two or three weeks I've managed to figure out most of its innards and how things work.
However, one thing is still bothering me - what's the basic difference between Activities and simple forms? Well, I know Android doesn't have such thing as a 'form', but by that I mean a fullscreen layout of elements that has an underlying class and all its functionality is executed in it, rather than in a process-wide class (Activity, to be precise).
As long as I understand, Activity is a separate process that's instantiated by OS to perform some actions that are basicly independent of the whole application. That also means that we can run only one of the application's activities, and it will still perform all of its functions without needing the whole application to be loaded. For example, if we have a movie player that can also convert movies from one codec to another, we can implement that functionality as a separate Activity so that other applications, like file managers, will also be able to convert movies between codecs using only that Activity, and not the whole application.
And that seems perfectly straightforward. The question is - why is everybody using separate Activities for functionality that cannot be separated from the application? In other words, people generally use Activities where I think simple forms within the same process would be more appropriate. For instance, I've seen people using a separate Activity for things like application settings, which obviously wouldn't be be launched outside the app itself, or editing application-specific data, which wouldn't be done outside the app as well, since the data to be edited should be selected from a list only known to the application.
Another example right from my experience - a unit converter application. It has a main menu with a GridView of units' categories, in each category there is a list of units and by clicking any unit we have a 'calculator' form for entering value that we want to convert. If I'd been doing that like everyone suggests I'd have three Activities - one for the main menu, one for the list of units and one for entering the value. But why? Why would I want to launch any of those three Activities separate from the application? If I'd want to launch main menu Activity - well, why not launch the whole application then? If I want just a list of units - again, just launch the whole application, it's not like some Facebook client is going to convert values between pressure units (since the list of units covers only one category at a time). And launching an activity for the calculator simply would not work, since it should return to the list to perform conversions and you'd have no list activity launched.
And anyway, even if I'm wrong and people use it wisely there's still an issue that Android SDK doesn't really provide any support for forms as I'm used to. Yes, there are things like ViewAnimator, ViewSwitcher etc. But all they do is switch layouts in their place, and that is hardly switching between forms as such. So the only choice to get close to that functionality at least is to use Activities. And we're back to the square one.
So to put it simply - am I missing something from the Android philosophy? Because I'm pretty sure that using a separate Activity (and a separate process as a result) for every single form in the application is an overkill. And if it really is and everybody knows that - why doesn't Android have any substantial form switching mechanism?
Thanks in advance for any clarification on this issue.
An activity isn't spawned in a separate process (unless you explicitly tell it to). Everything in your APK will be spawned in your process. Even if another application is using your Activity for whatever reason.
You can make your Activity "effectively" private to your application by not assigning any intent-filter to it in your manifest.
For the examples given, a form is equal to an activity. That isn't a universal statement as you delve deeper into Android, but for a beginner that's a decent analogy to make. Another common analogy is that Activities are more like web pages than traditional forms based UI.