QRCode Generator Tutorial

2 weeks ago I conducted an Android Training Workshop for CodeAndroid Singapore meetup at Google office. I have designed a tutorial to teach newbies the basic concepts of Android development. In this tutorial, developers learn the basics of Activity, View, Intent, and HTTP request. Developers were taught to create an application called QRTalk.

QRTalk allows user to type in some text message. It uses Google Chart API to encode this message and generate a QR code image. This image is then displayed in a WebView.

URL imageURL = new URL("http://chart.apis.google.com/chart?cht=qr&chs=350x350&chl=hello+world");
Bitmap qrBitmap = BitmapFactory.decodeStream(imageURL.openStream());
imageView.setImageBitmap(qrBitmap);

This is what I have learned while developing the tutorial. With 1 line of code, I am able to make a HTTP request and turn the HTTP response into a Bitmap object instance.

Lesson learned:

  1. Use more images in slides. Too much words on slides make it hard for people to absorb, and makes the presentation very dry.
  2. Cannot assume audience knows what is QR code.

Links

Posted in Tao Of Programming at February 11th, 2011. No Comments.

[Android] Activity Lifecycle

I have completed my iPhone application, now waiting for my boss to come out with a splash screen. My next project is to port the iPhone application to Android. I am now a newbie again.

An Android application is made out of at least 1 component. There are 4 types of components: Activity, Service, BroadcastReceiver, ContentProvider. In this post I am going to talk about the lifecycle of an Activity. Throughout the lifetime, the system will invoke some of the methods: onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy(), and onRestart(). In fact all, except onRestart(), will be invoked at least once.

When a new instance of an Activity is launched, it will go through the follow stages: onCreate, onStart, onResume. When the Back key is pressed, it will go through the following stages (before termination): onPause, onStop, onDestroy. If a Home key is pressed, instead of terminating the application, it is suspensed (hidden from view). A suspending activity will go through the following stages: onPause, onStop. When an activity comes back from suspension, it will go through the following stages: onRestart, onStart, onResume. I have printed out the lifecycle diagram and put it on my desk.

Development Tips:

  • LogCat allows a developer to view the system debug output. In Eclipse you can find it at Window -> Show View -> Other… -> Android -> LogCat. Sometime LogCat does not display anything because no device is selected yet. You can select the device to monitor in Window -> Show View -> Other… -> Android -> Devices. If you are woking in DDMS perspective everything will be loaded for you.
  • Use the Log in your application to output log messages.

Reference: Application Fundamentals

Posted in Tao Of Programming at June 26th, 2009. 2 Comments.