Android Mobile App

Warning: This blogpost has been posted over two years ago. That is a long time in development-world! The story here may not be relevant, complete or secure. Code might not be complete or obsoleted, and even my current vision might have (completely) changed on the subject. So please do read further, but use it with caution.
Posted on 11 Apr 2010
Tagged with: [ Android ]  [ joindin

When you visit PHP conferences nowadays, you’ll notice a lot of talk about the website ( It’s basically a site where you can register a conference, all the lectures and as a visitor of those conferences, let the speakers know about what you think off the lecture. It’s a very good way for speakers to learn and perfect their presentations. It’s also a pretty awesome site (who’s code is available on github!) and new features are added around the clock.

A few weeks ago, somebody launched the Iphone application in which you can add comments the easy way. Since I do not own an Iphone (nor ipad, ipod, macbook, or come to think of it, anything from Apple) it’s pretty useless for me. But I do have a Android powered phone so created a android version for Joind.In.

Suffice to say, it’s been running for a few weeks now, so I cleaned up the source :), and open sourced it so it’s for everybody to download at github to keep in the spirit of the original site.

I’ve also published it onto the Android Market, so you can download it by scanning this QR code (from your mobile off course) or by just clicking this link

(download the Android App from the Android Market)

This post is not about how to create an android application. There are many other sites who can provide you with much more info about that subject. However, I will tell you a bit on what creating an android app feels like, starting from scratch with no previous knowledge about the android environment (although some Java knowledge would be nice)

Getting started

Android development is the easiest when working with the Eclipse IDE. After adding the android SDK, you get a very good integration and most of the work will be done for you. You get a virtual device (the AVD) in which you can test your applications. However, initial loading can take a long (up to 5 minutes) time. It took me a few hours until I realised you can actually leave the AVD open when you recompile your application :(

If you close the AVD, you have to wait a few minutes again so don’t do that too often. Together with the AVD you get all kind of neat stuff: you can test your app on different settings (set your phone to roaming profile, send text messages, simulate incoming phone messages, display the file system etc etc). You can control almost everything so you do not even have to own an real life android phone in order to create applications… sweet!

Note that you don’t HAVE to use Eclipse. Since everything is open source you can develop anything the way you like.. How cool is that nowadays? An environment/API where YOU decide how to use it :)

Meet activities and layouts, your new  best friends…

Android Applications are based on activities. Every activity in itself is sort of a process which can be run by your phone (in your application settings you decide which activity is the startup activity). Every time you move to another screen, you “stack” another activity on top of the first one. When that activity is finished, you move back to the original activity. This is all documented in the android activity life cycle documentation, which is a very important diagram and very easy to understand. The picture below is a flowchart of all the activities (and how they are called) that the Joind.In app is using:

(Almost) every activity has a layout. This is a simple XML file with the layout textually described which get parsed by android and displayed on the screen. It automatically takes care when you flip your android to landscape so your app probably is usable both ways (unless you write something that doesn’t really use layouts, like a fullscreen game or something).

While developing things for the first time, you will run into lots of problems: how do i do this, how do I set this text color to red? I want this textbox left aligned instead of right etc etc.. There are lots of sites with “beginner” questions so don’t worry about it too much.. Just find examples, UNDERSTAND what they do (don’t copy+paste, you’ll never learn it that way) and continue.. If your first app will take 10 hours to complete, your second app will probably take only two.

There are a few catches when it comes to android programming I’ve noticed. Maybe they are indeed catches, or maybe it’s just me not knowing how to do them correctly. Anyway, here is the list:

  • All activities must be added to your AndroidManifest.xml. If you forget to add one, you cannot start the activity and you’ll be figuring out what is wrong for a very long time.
  • Making customized lists (for instance, a list with userdata which you can scroll up and down in) needs a very complex setup with list adapters etc..  Not only makes this more complicated than it should, but also very slow since for every row in your list, android has to fetch the XML with the layout, parse it, “compile” it into the actual layout etc.
  • Adding items to spinners must be done in your onCreate() function. You cannot add them in your layout XML files.
  • Event callbacks the same,  they must be added in your onCreate() function.
  • You have to be VERY CAREFUL when dealing with global resources like database-connections that get shared between activities. Sometimes, an activity gets closed, but a thread from that activity is still running. This thread might use a resource that you have destroyed during the closing of the activity.
  • Background processing should be done in separate threads. Not a problem, but those threads occasionally need to update the UI (for instance, display that something went wrong). This cannot be done from a thread, unless it’s a RunnableUI thread. It means you sometimes have to create another thread inside the already existing thread, just to display some text on screen.. Get’s very confusing as a beginner.

There are some really cool features I’ve stumbled upon:

  • You get the power over a very large set of libraries. It’s very easy to use most of them (like org.json, org.apache etc)
  • Once you get the hang of activities and layouts, writing the interfaces is a breeze so you can just concentrate on the business logic very quickly.
  • You can edit the layout XML’s yourself, our use the designer. (I prefer creating the XML myself)
  • Most things like creating preferences etc are already present, so building those is just writing (or designing) a simple XML file.
  • Theming is a breeze. I’ve spend a long time changing all backgrounds, button colors etc before I found out you can just set the theme “Theme.light” in your androidManifest.xml  :)
  • If you don’t know how things work, you just browse through android source (got that apple?)

Anyway.. writing apps for android is cool and easy.. You probably need some java experience (and the java way-of-thinking) before you can write something, but on the other hand, java in itself is fairly easy to comprehend. So get off your lazy PHP-butt, and start writing some cool android apps :)