Archive for July 28th, 2010

Android Development (from noob, to less noob) pt1

For the past week I’ve been making an android application on my fancy Desire phone running Android 2.1 Google’s phone operating system, manufactured by HTC from the Telstra Network (throwing in company names there in case I can get some free shit from them). It’s basically a contact list type application so that you can contact people within the organisation without needing to add them to your phone contact list, separating your personal contact list and work contacts. I feel that there the function of separating your person life and work life is very important, especially when your best friend’s name is John Miller and your boss’s name is John MacIntosh, a misclick and understood message could get you into a life of strife. I also don’t see the usefulness of having work contacts in which you only need to call Mon-Fri taking up space on your contact list. So essentially the loose brief for this app  is to create a contact list of people within the organisation.

I’ve never really developed anything useful before, or outside of university life. The software development cycle is a conceptual idea to me and I’ve never really live through it. However, upon returning to the lifestyle of work and/or working for ‘the man’, I’ve had to make sacrifices and do what ‘the man’ tells you to do. Which includes returning to the spiteful days of using java… (I remember those days. It was a dark world out there).

Of course, being Google technology, there’s a LOT of tutorials out there. This is great to start learning the android environment, the java coding complexities, and understanding how everything works. There’s also the assumption you actually know stuff, things, whatever. If you’ve been out of the loop like me, then well… you’re pretty much screwed. So what I really wanted to write was a somewhat meaningful post about my experience with the android platform and creating a noobish application for it, in terms that the local Penshurst butcher could understand (maybe there’s free sausages for me).

To begin with, you need an IDE. I don’t know how anyone can deal with Java without an IDE (Integrated Development Environment). I would say it’s impossible, and if someone actually manages to build applications without an IDE, well I have a new god to worship. In short, Java is confusing and an IDE is required. The IDE of choice is Eclipse, and there’s a reason for that. Google has been nice enough to give us a tutorial in how to install the Java SDK, Eclipse IDE and the plug-in’s required. You can find that link here, I see no point in reinventing the wheel. I will summarise it; you’ll need to install Java SDK, then get the Android SDK, install Eclipse, do some settings and install some plug-ins. Then you’re ready to tackle some tutorials.

To get anything working, you need to create an Emulator (also known as Android Virtual Device or AVD). This will create a window in which looks like an Android phone, so you can test your application. To do this, you need to install the AVD plug-in which you should already have, then in Eclipse go to ‘Window’ in the menu and there’s an option for the ‘Android SDK and AVD Window’. Here you’ll be able to create an emulator of an Android Version. I’m using 2.1 because it’s the version my phone uses, and the phones in the company are using. It’s safer to build something in earlier versions, usually applications are forward-compatible so this application would run on anything 2.1+ (including the new 2.2 Froyo build).

Now, if you wanted to run and compile something, you’ll need to point your application to that Emulator you just made. Starting an emulator takes a bit of time, it might look like it’s frozen but it is doing something. So that takes care of building an AVD and running/compiling an app. When compiling your code, make sure you have a .java file selected in your /src directory and not an .xml file, because often using the ‘Run’ command will compile just the xml and fails, making a .out.xml file or whatever. I’ve done this often when adding Activities to my Manifest file and not realising, and Eclipse will try to render the XML file and give you errors, and make a new .out.xml which you need to delete. This might not make sense now, but when the problem happens, you’ll be glad you knew this.

The Manifest file is important. I never really understood what the function of it was until I made something. The manifest file is an XML file that is automatically generated when you first create your android project. It does need tweaking however, for every Activity (Class) you make in your project, you need to write this into the Manifest file. Why? Well I believe the Manifest is the file that gives permissions, themes, labels and what-not to the Activity. Also, your application won’t compile without it, so if you’re stuck and wondering why your application doesn’t compile and you just added a new class, then this is most likely your problem. It also gives permissions to your app.  Once I find a good code snippet embedding plug-in for WordPress, I’ll post it below.

To create User Interfaces, you don’t need to create them in Java (thank god, gone are the days of swing!). You will make them using XML. You can find this in the res/layout directory. I would suggest playing around with the ones on the google android resource site, it has many examples of different views and the link can be found here. I’m a graphical user interface-y person and coding interfaces seems difficult for me at the moment, I am waiting on the App Inventor to provide me with a drag and drop interface builder in which I can then copy and paste the XML code.

So to finish up part 1:

  1. Install the SDK’s, Eclipse and the Plug-ins
  2. Create an Emulator (Android Virtual Device)
  3. Create a Project
  4. Ensure that Manifest file is kept up to date with your changes such as adding Activities.
  5. User Interfaces are made with XML