CS 185C/286 - Lecture 1
Cay S. Horstmann
Lecture 1 Quiz 1
Put your answer into Piazza.
Which of the following is true according to Programming Android Chapter 1?
- You should use OpenJDK, not the Oracle JDK, for Android programming.
- You should install Eclipse in your home directory, not in
- The ADT can be installed into Eclipse, NetBeans, or IDEA.
- To run your app on your phone, you must first become a registered developer.
- Operating system (Linux kernel)
- Hardware support: Camera, GPS, accelerometer
- Telephony (voice and data) and Wifi
- Custom 2D graphics library, OpenGL based 3D graphics
- Dalvik VM
- Application framework
- Core apps: webkit-based browser, contacts, etc.
- Media support, including H.264
- SQLite database
- 2003 - Android Inc. startup founded
- 2005 - Google buys Android Inc.
- 2008 - Android 1.0 released
- 2009 - Android 1.1, 1.5, 1.6, 2.0, 2.1
- 2010 - Android 2.2, 2.3
- 2011 - Android 3.0 (tablets only)
- 2011 - Android 4.0, unifies 2.3 and 3.0
- 2012 - Android 4.1, AKA Jelly Bean
Android and Java
- Use Java to write Android applications
- Subset of standard Java library, adapted from Apache Harmony
- Application framework completely different from standard Java
- Comparable to Blackberry (pre 10) programming
- Unlike BlackBerry or Java ME phones, no Java Virtual Machine
- Java class files converted to Dalvik VM
- Each app runs in separate Linux process running a Dalvik instance
- Dalvik machine code (DEX) optimized for small memory footprint
Android App Components
- Activity: a UI screen
- Service: lengthy job without UI, e.g. playing music
- Broadcast receiver: reacts to system or app broadcasts
- Content provider: make data available to other apps
- A particular app can have components of some or all of these types
- Each component is a Java class
Android Development Toolkit (ADT)
- Eclipse based IDE + command line tools
- Runs on Linux, Mac, Windows
- Uses regular Oracle JDK
- Can plug into regular Eclipse
- Easier to download the Eclipse + ADT bundle
- Ok to have multiple versions of Eclipse—even on Windows
- Supports multiple SDK levels
- We'll target 2.2 for our projects since it captures 97% of the market.
- Android Virtual Device (AVD): Phone emulator
- You only clone a repo once.
- Always run
git pull before you do anything else
git add to add files to the “staging area”.
git commit -a -m "..." to commit the staged files.
git push origin master to update the server.
- Version control is only for files that are
- not automatically generated
.gitignore to list files that should not be checked in.
- Bring your laptop to the lab
- You will work with a buddy
- One of you writes code, the other types up answers
- Switch roles each lab
- Submit lab work to git
Checking out Your Repo
- In your home directory, run
git clone ssh://firstname.lastname@example.org:62222/Lastname_Firstname cs185c What happens?
If you got a warning, that's ok. But if you got an error, that needs to be fixed before you can go on.
ls -a cs185c What do you get?
Getting Started with Android Programming
~/cs185c/workspace as your workspace
- Select File -> New Android Application
- App name lab01, everything else default
- Next, next, next...finish
- Close welcome screen to see your project
srcis the Java source,
res are the UI resources
- What source files were generated by the wizard?
- Where does the "Hello, World" message come from?
- Where is the class
Running Your Program
- Run your program by clicking on the green Run button or selecting Run from the Project menu. What happens?
- Click Next.
- Select Launch a new Android Device. What happens?
- Click on the Manager button, then on New
- Set the AVD name to
nexussand choose Nexus S for the device
- Click Ok, close the device manager. Click Refresh
- Run the program again. What happens?
Changing the Message
We want to change the message to Hello, Dave.
- Does the application source file contain the string
- Click on
activity_main.xml in the Package Explorer and then on the
activity_main.xml tab next to the Graphical Layout tab. What do you see?
- What happens if you change
- Ok, that couldn't have worked. Look inside
values/strings.xml. What do you see?
- How do you change the message? Be sure to run the app.
- Why do you think that the message wasn't stored directly in the
We want to add an image. Here's one of Dave.
- Move the image to the
- Go to
activity_main.xml and click on the Graphical Layout tab. Select Images & Media and drag an ImageView on the screen. What happens when you drop it?
- Hook up the 2001_dave.jpg file.
- Try running the app. What happens?
- Look in the Problems tab. What's the problem?
- Double-click on the error message. What's really the problem?
- Why shouldn't you fix it by editing R.java?
- How can you fix the problem?
- Now run the program. What happens?
Checking in a Project
find cs185c. What do you get?
- What bad thing would happen if you checked all these files into version control?
- Give an example of an automatically generated file that should not be checked in.
- Give an example of a platform-dependent file that should not be checked in. (You may need to poke into some Eclipse files with a text editor.)
- To make sure that you don't check in inappropriate files, place a file named
.gitignore into the
~/cs185c directory. Note the dot in
.gitignore. The file should contain the following:
.DS_Store Now run
git add workspace/lab01 and
git status -s in the
~/cs185c directory. What happens?
You should see a listing of files that haven't yet been submitted to version control. None of them should be class files, metadata files, or generated files. Check with me if this looks wrong.
git commit -a -m "Done with lab 1"
git push origin master What happens?
- To see that you did it right, change to
/tmp and clone your repo again. How did you do that?
- What files did you get?
Reading Before Next Class
- Programming Android Ch. 5