CS 185C/286 - Lecture 1

Cover page image

Cay S. Horstmann

Lecture 1 Quiz 1

Put your answer into Piazza.

Which of the following is true according to Programming Android Chapter 1?

  1. You should use OpenJDK, not the Oracle JDK, for Android programming.
  2. You should install Eclipse in your home directory, not in /opt.
  3. The ADT can be installed into Eclipse, NetBeans, or IDEA.
  4. To run your app on your phone, you must first become a registered developer.

Android Components

Android History

Android and Java

Android App Components

Android Development Toolkit (ADT)

git Basics

Git workflow


Checking out Your Repo

  1. In your home directory, run
    git clone ssh://git@zoidberg.cs.sjsu.edu: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.

  2. Run
    ls -a cs185c
    What do you get?

Getting Started with Android Programming

  1. Run ~/adt-bundle-linux-x86/eclipse/eclipse
  2. Create ~/cs185c/workspace as your workspace
  3. Select File -> New Android Application
  4. App name lab01, everything else default
  5. Next, next, next...finish
  6. Close welcome screen to see your project
  7. srcis the Java source, res are the UI resources
  8. What source files were generated by the wizard?
  9. Where does the "Hello, World" message come from?
  10. Where is the class R defined?

Running Your Program

  1. Run your program by clicking on the green Run button or selecting Run from the Project menu. What happens?
  2. Click Next.
  3. Select Launch a new Android Device. What happens?
  4. Click on the Manager button, then on New
  5. Set the AVD name to nexussand choose Nexus S for the device
  6. Click Ok, close the device manager. Click Refresh
  7. Run the program again. What happens?

Changing the Message

We want to change the message to Hello, Dave.

  1. Does the application source file contain the string "Hello, World"?
  2. 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?
  3. What happens if you change @string/hello_world to @string/hello_dave?
  4. Ok, that couldn't have worked. Look inside values/strings.xml. What do you see?
  5. How do you change the message? Be sure to run the app.
  6. Why do you think that the message wasn't stored directly in the activity_main.xml file?

An image

We want to add an image. Here's one of Dave.

  1. Move the image to the ~/cs185c/workspace/lab01/res/drawable-hdpi directory.
  2. 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?
  3. Hook up the 2001_dave.jpg file.
  4. Try running the app. What happens?
  5. Look in the Problems tab. What's the problem?
  6. Double-click on the error message. What's really the problem?
  7. Why shouldn't you fix it by editing R.java?
  8. How can you fix the problem?
  9. Now run the program. What happens?

Checking in a Project

  1. Run find cs185c. What do you get?
  2. What bad thing would happen if you checked all these files into version control?
  3. Give an example of an automatically generated file that should not be checked in.
  4. 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.)
  5. 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:
    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.

  6. Run
    git commit -a -m "Done with lab 1"
    git push origin master
    What happens?
  7. To see that you did it right, change to /tmp and clone your repo again. How did you do that?
  8. What files did you get?

Reading Before Next Class