Difference between revisions of "BTC640/Mobile"

From CDOT Wiki
Jump to: navigation, search
Line 1: Line 1:
= Lecture =
+
= 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.
 
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.
+
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 ==
 
== Android development environment ==
Line 19: Line 19:
 
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.
 
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.
  
 +
* Open up the Android SDK and AVD Manager in Eclipse
 +
* Create a new virtual device
 +
* Give it a name (whatever you want), select a target (there's only one choice)
 +
* This is important: '''Do not create a large SD Card'''. Since everything is in RAM you only have a few hundred megs of 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.
 +
* Start your device, and wait for it to boot. You can play around in there, this is what an Android phone is like.
 +
* Leave the emulator running, and go back to eclipse. You can close the SDK and AVD Manager now.
  
= Lab =
+
== 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.
 +
 
 +
* 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.
 +
* Have a look around, interesting parts are:
 +
** The src/ with the single Java file. This is all the source code your app has at this point.
 +
** 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.
 +
*** AndroidManifest.xml - information about your app, its platform and permission requirements.
 +
*** 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.
 +
*** 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.
 +
*** 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.
 +
* 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).
 +
* 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.
 +
 
 +
= Lab submission =
  
 
This is a marked lab. Please submit it using Moodle (Lab5).
 
This is a marked lab. Please submit it using Moodle (Lab5).
 
In the lab you'll be doing some the same stuff that I've shown in class. You can use the live cd or create a more permanent Android development environment on your own machine. No point making it on the lab machines, unless you only want to practice the setup.
 
  
 
Submit a zip file (or another compressed format) of your project and a screenshot of the emulator running your code.
 
Submit a zip file (or another compressed format) of your project and a screenshot of the emulator running your code.

Revision as of 11:47, 11 February 2012

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

Unless you already have an Android development environment set up you will need to use the Andora 1.2 live CD. 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 CD is that you can test the operating system on the CD 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 CD, reboot, and tell your machine to boot from the CD. If you're using one of the lab machines - turn the switch to "External", put in the cd, 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 CD. 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.

  • Open up the Android SDK and AVD Manager in Eclipse
  • Create a new virtual device
  • Give it a name (whatever you want), select a target (there's only one choice)
  • This is important: Do not create a large SD Card. Since everything is in RAM you only have a few hundred megs of 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.
  • Start your device, and wait for it to boot. You can play around in there, this is what an Android phone is like.
  • 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.

  • 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.
  • Have a look around, interesting parts are:
    • The src/ with the single Java file. This is all the source code your app has at this point.
    • 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.
      • AndroidManifest.xml - information about your app, its platform and permission requirements.
      • 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.
      • 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.
      • 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.
  • 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).
  • 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.

Lab submission

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

Submit a zip file (or another compressed format) of your project and a screenshot of the emulator running your code.