intro 2 android


Intro to Android Development

Getting started

1. Install Android SDK (includes Eclipse; .

2. If using Windows & eclipse & Samsung Galaxy, install Galaxy driver.

– Install Samsung Kies application.

• • Download from

Do not check Unified Driver Installer.

– No need to install Galaxy drivers when using Linux + eclipse.

Download Albie (AIMv1).

1. First, make sure that your Eclipse Java ADT is installed and running correctly.

– File -> New -> Android Application Project.

– Call it Test and make sure you can build and run it.

2. Unzip but do not unzip it directly into the eclipse workspace.

– The directory, AIMv1, will be created.

3. File --> Import...

– Expand Android folder. – Select 'Existing Android Code Into Workspace.' – Next.

Download Albie (continued).

4. Use Browse to find the Root Directory which is AIMv1 (unzipped above).

– Check 'Copy projects into workspace.' – Finish.

5. The AIMv1 folder should now appear in the eclipse Package Explorer.

6. You may ignore the error message, "Unable to resolve target 'android-#.'"

Download Albie (continued).

7. Start with a fresh build by doing the following: – – Select AIMv1 in Package Explorer.

Project -> Clean – Run -> Run As -> Android Application • Ignore any and all directories/folders with CVS in the name.

ac·tiv·i·ty [ak-tiv-i-tee] – noun, plural ac·tiv·i·ties.

1. the state or quality of being active: There was not much activity in the stock market today. He doesn't have enough physical activity in his life.

2. a specific deed, action, function, or sphere of action: social activities.

3. work, especially in elementary grades at school, that involves direct experience by the student rather than textbook study.

4. energetic activity; animation; liveliness.

5. a use of energy or force; an active movement or operation.

• from

Definition: Activity

• Activity – “An application usually consists of multiple activities that are loosely bound to each other.

– Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time.

– Each activity can then start another activity in order to perform different actions.” •

Definition: Activity

• Activity – “An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.

– Each activity is given a window in which to draw its user interface.

– The window typically fills the screen, but may be smaller than the screen and float on top of other windows.” • Ibid. (That’s fancy! I’m working on using op. cit.)

Associated with the main activity is an XML file that describes its UI layout.

Definition: Activity

• Activity – “Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack").

– When a new activity starts, it is pushed onto the back stack and takes user focus.

– The back stack abides to the basic "last in, first out" stack mechanism, so, when the user is done with the current activity and presses the Back button, it is popped from the stack (and destroyed) and the previous activity resumes.” • Ibid.

These Java files are automatically generated. Do not edit them!

1. AbsoluteLayout 2. DrawerLayout 3. FrameLayout 4. GridLayout 5. GridView 6. LinearLayout 7. ListView 8. RelativeLayout 9. SlidingPaneLayout 10. WebView



xml – extensible markup language

Example: prolog John Smith

xml – extensible markup language

Example: John Smith

xml – extensible markup language

Example: John Smith

xml – extensible markup language

Example: John Smith

xml – extensible markup language

Example: attribute name John Smith

xml – extensible markup language

Example: John Smith city="4000 Stavanger" country="Norway“ /> Empire Burlesque Special Edition 1 10.90

Note: The shiporder tag has both attributes and contents.

Hide your heart 1 9.90

The manifest lists and contains information about all of the activities in the application.



Setup on PC

1. Install eclipse + android (see


– Instructions are there if eclipse is already installed.

2. Enable virtualization in BIOS.

– On a Lenovo T510, press F1 when you see the “ThinkVantage” message.

Setup on PC

Two ways to run Android apps: 1. Create a virtual device.

• Note: It takes some time for the emulator to start. So don’t close it once it starts! (Use the ‘back’ button to stop you application.) 2. Use a real android device. BEST!

Setup on PC for Galaxy

• Install the Android USB driver for Samsung.

– First, install Samsung Kies software.

• • This will take some time (~1 hour).

Then it will update itself again.

– Then plug in the Galaxy; your laptop will install a number of drivers.

– If all is well, when you run adb devices on your laptop, you will see your device listed.

Steps to run your Android application

1. Right-click on the name of your project in the Project Explorer pane.

2. Choose your Android device (or virtual device). (See next slide.)


Setup on Android device

• Setting --> Security --> Unknown source – Make sure it’s checked.

• Settings --> Developer options --> USB debugging – Make sure it’s checked.

Comments about layouts

• Layouts may be nested/hierarchical.

• See http://www.learn tutorial/ for a layout tutorial.


Writing to the log

import android.util.Log; … Log.v( "andy1", "MainActivity.sendMessage: hello" ); d – debug e – error i – information v – verbose w – warning

Accessing the log file via eclipse


Android widget classes

• • • • • • • • • • More than 100!

– See summary.html


Button EditText ImageButton ImageView NumberPicker PopupMenu RadioButton, RadioGroup Toast ToggleButton


Palette contents disappear when Show Previews is selected (default)


• • Activity – app/Activity.html

Intent – content/Intent.html


• • • • • • • • •;;;;; summary.html

How to disable the native Android browser (not Firefox, etc.) from “going mobile.”

1. Open browser 2. Type "about:debug" in the address bar. Press "go.“ Nothing will happen, this will only enable more options in the menu.

3. Go to menu. (Notice ‘Dump V8 counters’ at bottom.) 4. Choose Settings -> Debug -> UAString.

5. Select "desktop."