BTC640/Mobile

From CDOT Wiki
Jump to: navigation, search

Lecture/Lab

This week we'll be looking at how to develop for mobile devices. On a small screen there is little room for anything, thus presentation is king.

We will set up an Android development environment including an emulator, create a simple Android application, and a small webpage geared to mobile. You'll do the same stuff in the lab that I showed you in class.

Android development environment

Note: Andora has not been updated for a long time, this section will be rewritten once I figure out what works in our labs this semester.

Unless you already have an Android development environment set up you will need to use the Andora 1.2 live DVD. This is a modified version of the popular Fedora linux distribution, modified by Raymond Chan to include the Android development tools including Eclipse with all the plugins, the Android SDK, and tools like the Android emulator.

The point of a live DVD is that you can test the operating system on the DVD without installing it or making any changes whatsoever to the harddrive. That means that all of the changes you make during the session, including projects and virtual devices you created will be gone as soon as you reboot. Everything is stored in RAM.

If you're using your own machine - simply put in the DVD, reboot, and tell your machine to boot from the DVD. If you're using one of the lab machines - turn the switch to "External", put in the DVD, and reboot. You do not need an external harddrive.

Once it boots - click the login button. Then wait for Eclipse to start, which will happen automaticlly. Note that this environment is a lot slower than it would normally be because everything has to be read from the DVD. Eclipse will start automatically, wait for that.

AVD

An Android Virtual Device is a virtual machine that runs Android, it's great for testing applications. You can normally create virtual machines with different Android versions but on Andora we only have the 2.3.3 SDK installed. You still can choose different screens and other hardware parameters.

We want to be able to test the app we create even if you don't have an Android phone, so we'll create an AVD.

  1. Open up the Android SDK and AVD Manager in Eclipse
  2. Create a new virtual device
  3. Give it a name (whatever you want), select a target (there's only one choice)
  4. This is important: Do not create a large SD Card. Since everything is in RAM you only have a few hundred megs of fake disk space, so even though a 16MB SD card is unrealistic, we won't need more than that for anything we'll be doing. If you create a much larger SD card you will simply run out of virtual disk space and everything will crash.
  5. Start your device, and wait for it to boot. You can play around in there, this is what an Android phone is like.
  6. Leave the emulator running, and go back to eclipse. You can close the SDK and AVD Manager now.

Sample App

We're going to create an app that does almost nothing, but that should be good enough for one lecture and one lab.

  1. Create a new Android project in Eclipse. Give it a name and a package name such as ca.senecacollege.yourlearnid You do not need a test project.
  2. Have a look around, interesting parts are:
    1. The src/ with the single Java file. This is all the source code your app has at this point.
    2. XML files, which can be viewed using a pretty graphical viewer or a simple text/xml viewer by choosing the tab at the bottom after you double-click on the file in Eclipse.
      1. AndroidManifest.xml - information about your app, its platform and permission requirements.
      2. res/values/strings.xml is the collection of translatable strings, similar to a POT file. If you add a new string in your UI you should add it here.
      3. res/layout/main.xml is the XML definition of the current layout of your app. You can do quite a bit in here without knowing a lot about Android or even Java.
    3. Note that the R.java file under "gen" is automatically generated by the compiler from your xml files, don't be tempted to manually edit it.
  3. Select your package in the package explorer, and click the green Run button. Run it as an Android application. This will compile your app and run it on your phone (if it's connected) or on the emulator (if it's running).
  4. Go back to main.xml and make the app a login screen. Change the hello world text (using an existing or new @string resource) to "YourName's fancy app", add username/password textviews and fields, and a button. Make sure your new fields and button text are @string resources.
  5. Experiment with other widgets and layouts available through the GUI.
  6. When you app is ready - export it as an unsigned application package.

Lab submission

This is a marked lab. Please submit it using Moodle (Lab8).

Submit:

  • A zip file of your project (this will be under the ~/workspace directory),
  • The APK file,
  • A screenshot of the emulator running your app