67
Build Your First Android App Session #1 10 May 2014

Build Your First Android App Session #1

Embed Size (px)

DESCRIPTION

The slides from the build your first android app course.

Citation preview

Page 1: Build Your First Android App Session #1

Build Your First Android AppSession #1

10 May 2014

Page 2: Build Your First Android App Session #1

Today’s Agenda

• Installation

• Coffee Finder

• Understanding Android

• Signing Our App

• Registering for Service

• Design Our UI

Page 3: Build Your First Android App Session #1

Agenda Continue

• Action Bars and Navigation

• Debugging

• Lists

• Maps

Page 4: Build Your First Android App Session #1

Installation

• Java SDK 6

• Android Studio

• Android SDK and Stuff

• Genymotion and VirtualBox

Page 5: Build Your First Android App Session #1

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

Page 6: Build Your First Android App Session #1

Installing Java

• Install as an Admin

• Keep the defaults

• Add Java bin folder to path

• And create JAVA_HOME

Page 7: Build Your First Android App Session #1

Installing Java

• Permit the install to make changes

Page 8: Build Your First Android App Session #1

Installing Java

• Click Next

Page 9: Build Your First Android App Session #1

Installing Java

• Once you completed installation…

• Add the Java bin folder to the Path…

Page 10: Build Your First Android App Session #1

Installing Java

• Click Advanced system settings

Page 11: Build Your First Android App Session #1

Installing Java

• Click Environment Variables…

Page 12: Build Your First Android App Session #1

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

Page 13: Build Your First Android App Session #1

Installing Java

• Also add a JAVA_HOME to your system variables

• This points to your Java 6 runtime

Page 14: Build Your First Android App Session #1

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

Page 15: Build Your First Android App Session #1

Installing Android Studio

• Again, install as an Admin

• Allow the install to make changes

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

Page 16: Build Your First Android App Session #1

Installing Android Studio

• Accept the defaults by clicking next

Page 17: Build Your First Android App Session #1

Installing Android Studio

• Let anyone use Android Studio

Page 18: Build Your First Android App Session #1

Installing Android Studio

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

Page 19: Build Your First Android App Session #1

Installing Android Studio

• So be sure to launch the studio

Page 20: Build Your First Android App Session #1

Installing Android Studio

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

Page 21: Build Your First Android App Session #1

Installing Android Studio

• Ignore this update! We will update from the app

Page 22: Build Your First Android App Session #1

Installing Android Studio

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

Page 23: Build Your First Android App Session #1

Installing Android Studio

• Click Update and Restart

Page 24: Build Your First Android App Session #1

Installing Android Studio

• Now that we are update, lets get our SDKs

Page 25: Build Your First Android App Session #1

Installing Android Studio

• If you see this dialog, click Open

Page 26: Build Your First Android App Session #1

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

Page 27: Build Your First Android App Session #1

Installing Android Studio

• Accept the licenses

• Click Install

Page 28: Build Your First Android App Session #1

Installing Android Studio

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

Page 29: Build Your First Android App Session #1

Installing Genymotion

• On Windows select the Genymotion / VirtualBox combo install package

• Again, I recommend installing as admin

Page 30: Build Your First Android App Session #1

Installing Genymotion

• Once installed, run Genymotion

• Click the plus sign to add a virtual device

Page 31: Build Your First Android App Session #1

Installing Genymotion

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

Page 32: Build Your First Android App Session #1

Installing Genymotion

• On the virtual Google Galaxy Nexus device

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

• You should get this dialog

• Click OK

Page 33: Build Your First Android App Session #1

Installing Genymotion

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

Page 34: Build Your First Android App Session #1

Installing Genymotion

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

Page 35: Build Your First Android App Session #1

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

Page 36: Build Your First Android App Session #1

Coffee Finder

• Click the new project button

• Fill in the blanks

• Use your own domain name!

• Click Next

Page 37: Build Your First Android App Session #1

Coffee Finder

• Just click Next here

Page 38: Build Your First Android App Session #1

Coffee Finder

• Change the Activity Name

• And the Layout Name

• Click Next

Page 39: Build Your First Android App Session #1

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

Page 40: Build Your First Android App Session #1

Coffee Finder

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

• Click OK

Page 41: Build Your First Android App Session #1

• logcat shows us logging messages from the device

• And there are a lot of messages…

• Luckily we can filter them

logcat

Page 42: Build Your First Android App Session #1

Understanding Android

• Android Open Source Project

• Alphabet Soup

• Project Structure

• Pages

• The Application Object

• Intents

Page 43: Build Your First Android App Session #1

The Android Open Source Project

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

• The Android Open Source Project

• Google Services

Page 44: Build Your First Android App Session #1

Alphabet Soup

• ADB - Android Debug Bridge

• ADT - Android Developer Tools

• AVD - Android Virtual Device

• DDMS - Dalvik Debug Monitor Server

Page 45: Build Your First Android App Session #1

Project Structure

• AndroidManifest.xml

• bin - executable

• libs - libraries

• res - resources

• src - source files

Page 46: Build Your First Android App Session #1

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

Page 47: Build Your First Android App Session #1

AndroidManifest.xml

• It is a XML document

• All elements must close

• Elements contain attributes and data

• The root element is the Manifest tag

Page 48: Build Your First Android App Session #1

AndroidManifest.xml

• Application tag

• Activities and Services

• Permissions

• Meta-data

Page 49: Build Your First Android App Session #1

Pages

• Activity

• Fragments

Page 50: Build Your First Android App Session #1

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

Page 51: Build Your First Android App Session #1

Coffee Finder

• Here’s what we got so far…

• We’ve got a lot of work to do

Page 52: Build Your First Android App Session #1

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

Page 53: Build Your First Android App Session #1

Registering for Services

• Google Maps Android

• http://bit.ly/1jsfeJc

• Registering with YP.com

• http://publisher.yp.com

Page 54: Build Your First Android App Session #1

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.

Page 55: Build Your First Android App Session #1

Designing Our UI

Here is the map page.

Page 56: Build Your First Android App Session #1

Designing Our UI

The details page.

Page 57: Build Your First Android App Session #1

Designing Our UI

And finally the settings page.

Page 58: Build Your First Android App Session #1

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

Page 59: Build Your First Android App Session #1

Our 2nd Page

• Create the MapActivity

• Create the map layout

• Register the new activity in the manifest

• Launch new activity from the old one

Page 60: Build Your First Android App Session #1

Create the Application Object

• Create the Application object

• Register the Application object in the manifest

• Set breakpoint to see it in action

Page 61: Build Your First Android App Session #1

Create the Constants Class

• Create the Constants class

• Add LOG_TAG to it

Page 62: Build Your First Android App Session #1

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

Page 63: Build Your First Android App Session #1

Converting JSON to POJO

• Introduction to GSON

• How does GSON work?

• Implement GSON in Code

Page 64: Build Your First Android App Session #1

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

Page 65: Build Your First Android App Session #1

More Map Activity

• Returning to the Listings Activity

• Via the Action Bar

• Via the Back button

Page 66: Build Your First Android App Session #1

Rendering a Map

• A Simple Map

• Positioning the Camera

• Adding the user’s location

• Adding Markers to the Map

Page 67: Build Your First Android App Session #1

Summary Session #1

• Google Maps

• Android Manifest

• Activities and Fragments

• Intents

• AsyncTask