Well, after he tragedy of the fire, I was really broke. I sold my Kindle DX for food/utility monies and have since deeply regretted it. So I started thinking about ways to come up with the cash to buy a new Kindle. Then I thought, “what better way to do that than to sell an app in the Android Market?”
So, I went back to basics and started reading Java books, this time I wanted to get it right. I started to fall asleep and changed my mind. So then I dove right into coding…
Along the way, actually I am still in the middle of coding the application, I found that the documentation from the Google Android Developer Site was alright, but not what someone like me needed. I have since found that if I need to recall some very bloated piece of Java/Android class/method/etc, it’s easier to just search Google and skip the Android Developer site. There are tons of references and real life error solving posts online. Now, I would like to contribute a few tips and tricks for the non-Java fluent crowd.
Take a deep breath.
1. Eclipse -_-
The IDE used for Android development Eclipse isn’t at all that great. Well, I can’t really say that, because I have only developed Android/Java with it. So maybe Google’s SDK occasionally breaks it? Anyways, sometimes it reports non existent errors in your code, and I found that by going to Project->Clean… in the top menu bar fixes that. Now, you can imagine, if you’re like me and don’t really understand Java that well, this can be such a nightmare. Eclipse will sometimes say this:
[2010-11-20 11:41:57 - My Cool Ass Application] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
[2010-11-20 11:41:57 - My Cool Ass Application] Please check logcat output for more details.
[2010-11-20 11:41:57 - My Cool Ass Application] Launch canceled!
This is cute and utterly annoying. In fact, this has caused me to completely give up on coding boated Android/Java for the day on a few occasions. waiting for the AVD to reboot – sucks. This Google Groups post says to restart the emulator. Yeah, thanks Google. At first I gave the emulator the benefit of the doubt and thought, “hey, my app has an mp3 compiled into it making it rather big (12MB), maybe I should move the mp3 to the SD Card upon installation or put the mp3 somewhere online and stream it to the system. Then I clicked on Settings->Applications->Manage Applications and the Android AVD said this:
You do not have any third party applications installed.
After hours of research, I figured out that this error means nothing at all. If you reattempt to upload your project (CTRL+F11) it will not solve the non-existent error. This means that you need to either restart the AVD (Android virtual machine you are testing the project on), or sometimes it gets so bad you need to restart the emulator too. If you still get it, you need to delete the AVD and create a new instance:
Window->Android SDK AVD Manager->Delete->New...
Sometimes the Error console will say that it just brought the old version to the front screen! This is AFTER you tell the IDE to upload and install a new version. How disrespectful!
Speed is another thing to consider. I use CTRL+F11 to hurry up and upload the app to the device and run it. If you edit your XML file to say wrap the contents of the LinearLayout tag in ScrollView tags, this causes Eclipse to slow down to a crawl. Not only that, the project will be loaded into the emulator AVD and you will see a nasty red X next time you go back to the XML to view it and not know why it’s there. – Take your time with this gigantic Cthulhuian slow IDE.
Two more things I’d like to vent about with this – you cannot drag selected text in the XML editor window. Over the last few years or so I have come to love that feature in applications. I try once, then I should remember not to do it again. I do it twice shame on me. I do it three times – i swear out loud. Next is the fact that the XML editor doesn’t translate to the code itself from the design view. In Dreamweaver all of my experience has been with design, code, or split view. If you select an object in the design view you can switch back to the code view and it’s selected. This would be seriously useful in Eclipse as there are often elements that you don’t see (dynamically created, void of content atm, etc). Take a deep breath.
2. MediaPlayer VS. SoundPool
There is a HUGE difference between MediaPlayer and SoundPool. These Java classes play media (sounds, songs, videos, etc). What I think is odd is that I never knew that SoundPool existed! Yeah, if you casually broswe to the Audio Video section of the Android Developer site, it only mentions MeidaPlayer! If you are making an application that is going to play more than 7 sounds and you use MediaPlayer, it will force close no matter which version of the SDK you are running. In fact, if you create the MediaPlayer objects in the beginning of your main class, you will get a force close. I try to read the fine print in the debugger, but I can’t make heads or tails of it. Playing sounds, like Sound Board applications, video games, etc, should be coded to play sounds using the SoundPool. Sure, it’s like 10 more lines of code you have to reference (use Google), but it won’t force close.
3. Classes in Manifest.XML
Classes and Activities need to be in the Manifest.xml If you create a new class and forget to put it into the Manifest.xml file and you call it with Intent, you will get a force close. Hell, if you call a different class using Intent, it (Java) scans all the classes in the Manifest.xml and matches them to what’s available and will force close too! After making a new class, make sure you re-open the Manifest.xml each time and add it. This is a step I forgot loads of times because I never really have that file open in the IDE.
4. Toast Objects
You can call a Toast object with one line. This is far nicer than what I used to use. The less amount of Java code the better when doing ANYTHING. Here is a good example of that:
Toast.makeText(getBaseContext(), "Say something cool!", Toast.LENGTH_SHORT).show();
Toast objects are those little grey boxes that pop up when you are notified in Android. You can completely customize almost anything you want, it just takes a significantly larger amount of code writing skill and time.
5. Life Cycle
The Life cycle of an Android Application is rather important to consider as well. Say you create a new class, activity and layout for that class. If you call that class (change windows, similar to “rooms” using the Nintendo DS IDE for programming with Nintendo DS), the current Activity will call onPause(); Now, according to Google, onResume(); get’s called when the old class gets brought back to the front:
This isn’t necessarily true. If you hit the back button to leave a class, and the old class is brought back to the front, onResume(); is not called. I haven’t tested this, but I am pretty certain that you need to use a button in the application to go back to the previous class to call onResume(); I found an awesome video about these where SleepyDog <-- Awesome coder! basically outputs what the Android application is doing at all times:
6. Android App Inventor
This is an online resource that you need special permission to use. Android App Inventor is a Java based (no surprise) web application that allows one to make cheeky little applications, like sound boards, picture frames, etc. I made a small app with it that plays a few of my songs. These songs are mp3′s that I had compiled right into the application. I maxed the size out (25MB for any Android Application) and tried to add it to the Android App Market. FAIL. You cannot add applications you created using this web app to the market. I tried downloading the apk unpacking it and resigning it then uploading it, wrong. I jumped through hoops trying to work around this and realized that anytime I do anything Android dev related I am jumping through hoops and essentially wasting man hours. I’d recommend using the buggy SDK with the Eclipse IDE.
jQTouch Preview from David Kaneda on Vimeo.
With an iPhone or iPod touch you can create a special icon file that is used when you add the web app to the home screen. Fully customizable via CSS, images, etc. While developing (for iPhone) I would recommend using the MobiOne iPhone emulator so you don’t have to waste your battery and/or time using a real device. The MobiOne is the best emulation tool for any mobile device I have had experience with.
Well that concludes this package of tips for the Android newbie. I hope this helps someone who is searching for answers!