Build Your First Android App Session #1

Preview:

DESCRIPTION

The slides from the build your first android app course.

Citation preview

Build Your First Android AppSession #1

10 May 2014

Today’s Agenda

• Installation

• Coffee Finder

• Understanding Android

• Signing Our App

• Registering for Service

• Design Our UI

Agenda Continue

• Action Bars and Navigation

• Debugging

• Lists

• Maps

Installation

• Java SDK 6

• Android Studio

• Android SDK and Stuff

• Genymotion and VirtualBox

Why are we using Java 6?

• Android does not run the Java Virtual Machine, JVM

• It runs an optimized version called the Dalvik Virtual Machine, DVM

• Because of this the current version of Java is immaterial to Android

Installing Java

• Install as an Admin

• Keep the defaults

• Add Java bin folder to path

• And create JAVA_HOME

Installing Java

• Permit the install to make changes

Installing Java

• Click Next

Installing Java

• Once you completed installation…

• Add the Java bin folder to the Path…

Installing Java

• Click Advanced system settings

Installing Java

• Click Environment Variables…

Installing Java

• We are going to modify the System variables

• Scroll up/down in the bottom box until you the Path

• Add the path to the Java bin folder to the end of the path

Installing Java

• Also add a JAVA_HOME to your system variables

• This points to your Java 6 runtime

Installing Java

• From the command prompt run the java command to display the version number

• If all is well it will respond: javac 1.6.0_45

Installing Android Studio

• Again, install as an Admin

• Allow the install to make changes

• The install isn’t signed, don’t panic

Installing Android Studio

• Accept the defaults by clicking next

Installing Android Studio

• Let anyone use Android Studio

Installing Android Studio

• Once you’ve installed successfully, we need to get the Android SDKs and stuff

Installing Android Studio

• So be sure to launch the studio

Installing Android Studio

• Don’t worry about this dialog, it just gives us a chance to upgrade old projects

Installing Android Studio

• Ignore this update! We will update from the app

Installing Android Studio

• Once you reach here, click the tiny “Check for updates now” link

Installing Android Studio

• Click Update and Restart

Installing Android Studio

• Now that we are update, lets get our SDKs

Installing Android Studio

• If you see this dialog, click Open

Installing Android Studio

• If this screen doesn’t come up on its own, click the Android with the down arrow icon

• Select all of the indicated downloads

• Click Install

Installing Android Studio

• Accept the licenses

• Click Install

Installing Android Studio

• Once you see this screen, just one more packaged to install!

Installing Genymotion

• On Windows select the Genymotion / VirtualBox combo install package

• Again, I recommend installing as admin

Installing Genymotion

• Once installed, run Genymotion

• Click the plus sign to add a virtual device

Installing Genymotion

• If you want to keep up with me, choose the Google Galaxy Nexus

Installing Genymotion

• On the virtual Google Galaxy Nexus device

• Drop the file: gapps-jb-20130813-signed.zip

• You should get this dialog

• Click OK

Installing Genymotion

• Once you get to here, you will need to reboot the virtual device by powering it down, then up

Installing Genymotion

• The first time booting completely up, it should ask for you Google account

Coffee Finder

• This is our app

• It is a small but full featured app

• It uses lists, maps, the action bar, tasks, 3rd party web services, and more

Coffee Finder

• Click the new project button

• Fill in the blanks

• Use your own domain name!

• Click Next

Coffee Finder

• Just click Next here

Coffee Finder

• Change the Activity Name

• And the Layout Name

• Click Next

Coffee Finder

• In order to run our app, click the run button, which looks like a green arrow at top near the center of the IDE

• Next to it is the debug button which we will also use a lot

Coffee Finder

• If you get the Choose Device dialog, be sure to to select Use same device…

• Click OK

• logcat shows us logging messages from the device

• And there are a lot of messages…

• Luckily we can filter them

logcat

Understanding Android

• Android Open Source Project

• Alphabet Soup

• Project Structure

• Pages

• The Application Object

• Intents

The Android Open Source Project

• Android as we think of it is composed of two parts:

• The Android Open Source Project

• Google Services

Alphabet Soup

• ADB - Android Debug Bridge

• ADT - Android Developer Tools

• AVD - Android Virtual Device

• DDMS - Dalvik Debug Monitor Server

Project Structure

• AndroidManifest.xml

• bin - executable

• libs - libraries

• res - resources

• src - source files

AndroidManifest.xml

• Every application must have one in the root directory

• Presents essential app information to the Android system

• Activities, services, the application object must all be defined in it

• It also controls the look of some elements

AndroidManifest.xml

• It is a XML document

• All elements must close

• Elements contain attributes and data

• The root element is the Manifest tag

AndroidManifest.xml

• Application tag

• Activities and Services

• Permissions

• Meta-data

Pages

• Activity

• Fragments

The Application Object

• A base class for those who need to maintain global application state

• You provide its name in the AndroidManifest file

• The Application object created before any activity or service

• When destroyed, app is finished

Coffee Finder

• Here’s what we got so far…

• We’ve got a lot of work to do

Signing Our App

• In order to use Google Maps, we need to know our apps two signatures

• One for debug, which we will get now

• And one for release, will do that next week

Registering for Services

• Google Maps Android

• http://bit.ly/1jsfeJc

• Registering with YP.com

• http://publisher.yp.com

Designing Our UI

I don’t do anything fancy. Just plain 3x5 cards. Makes it easy to

make changes and to play my design.

Here is the design of the listings page.

Designing Our UI

Here is the map page.

Designing Our UI

The details page.

Designing Our UI

And finally the settings page.

The Action Bar

• The Action Bar will be are primary UI.

• We will use it to move between the listings page and the map page

• And to go to the settings page

• Drilling down on either listings or map pages takes you to the details page

Our 2nd Page

• Create the MapActivity

• Create the map layout

• Register the new activity in the manifest

• Launch new activity from the old one

Create the Application Object

• Create the Application object

• Register the Application object in the manifest

• Set breakpoint to see it in action

Create the Constants Class

• Create the Constants class

• Add LOG_TAG to it

Calling a Web Services

• Make a direct calls to YP from DHC

• Describe all of the objects in it

• Create a class for each object

• Avoiding ANR

• Create an AsyncTask to load the data

Converting JSON to POJO

• Introduction to GSON

• How does GSON work?

• Implement GSON in Code

Creating a ListView

• Add the ListView to the layout

• Create a row

• Creating the ListAdapter

• Watching the ListView get filled

• Drilling to a list item

More Map Activity

• Returning to the Listings Activity

• Via the Action Bar

• Via the Back button

Rendering a Map

• A Simple Map

• Positioning the Camera

• Adding the user’s location

• Adding Markers to the Map

Summary Session #1

• Google Maps

• Android Manifest

• Activities and Fragments

• Intents

• AsyncTask

Recommended