1 of 19

Android 101: Intro to Android

Directed by Travis Smith

@iamtravisjsmith

2 of 19

Who is Travis?

  • Senior software developer at LunarLincoln
  • 2.5 years experience developing native Android and iOS apps
  • BS in CS from University of Florida

3 of 19

What is Android?

  • Android is a Linux-based operating system
  • Over 1.4 billion devices running Android
  • ~10 versions of Android are actively (commonly) being used today
  • Apps are natively written in Java
    • With a dash of XML and Groovy

4 of 19

Getting Started

  • Android Studio
    • Not Eclipse! Officially no longer supported.
  • SDKs
    • All you need should be included with Android Studio install
  • Emulators

5 of 19

Activities

  • An Activity is an entry point for user interaction
    • “Screen” ~ Activity
    • Typically each feature is its own Activity
  • Example Activities in a To-Do app:
    • Upcoming tasks
    • Create a new task
    • Completed tasks

6 of 19

Activity Lifecycle

  • Don’t panic
  • Blue boxes are Activity states
  • Green boxes are lifecycle methods

onResume()

onCreate()

onStart()

onPause()

onStop()

onDestroy()

Activity Shut Down

Activity Running

Activity Launched

App Process Killed

onRestart()

App with higher priority needs memory

Another activity comes into the foreground

User returns to the activity

The activity is no longer visible

The activity is finished or being destroyed by the system

User navigates to the activity

  • Most Activities only implement onCreate(), but it’s good to be familiar with this chart
    • Why? To set the layout!

7 of 19

Layouts

  • Android layouts are designed with XML
  • All elements can be described as Views or ViewGroups
  • Android Studio has a visual editor for layouts
    • I find it easier to edit the XML directly

8 of 19

AndroidManifest.xml

  • Sort of a summary of your app
  • Controls the name and icon for your app
  • Lists out all of your Activities, Services, etc.
  • Declares permissions your app will ask for
  • Does a ton of other stuff

9 of 19

Let’s make an app.

10 of 19

Creating a New Project

11 of 19

Why minSdkVersion 19?

  • Two reasons...

12 of 19

Create our First Activity

13 of 19

That was easy. Let’s step it up.

14 of 19

Sample App - What to make?

  • I wanted to cover a range of topics that you might use in your own apps
  • Some of the most common things I could think of:
    • Displaying lists
    • Asking users for permissions (API 23+)
    • Consuming REST APIs
    • Using hardware sensors
  • So I came up with the idea of making a small weather app that displays some data

15 of 19

SampleWeatherApp

  • https://github.com/travis-j-smith/SampleWeatherApp
  • It uses OpenWeatherMap’s public REST API which means you’ll need to make an account to obtain an API key
  • It asks the user for location permissions, then polls the GPS for a location reading
  • Then it passes the coordinates to OpenWeatherMap and gets back the weather conditions

16 of 19

What does the API give us?

{

"coord": {"lon":-86.78,"lat":36.17},

"weather":[

{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}

],

"base":"stations",

"main":{"temp":290.65,"pressure":1007,"humidity":68,"temp_min":290.15,"temp_max":291.15},

"visibility":16093,

"wind":{"speed":2.1,"deg":130},

"clouds":{"all":1},

"dt":1487903700,

"sys":{"type":1,"id":2533,"message":0.0061,"country":"US","sunrise":1487938999,"sunset":1487979458},

"id":4644585,

"name":"Nashville",

"cod":200

}

17 of 19

Let’s see some code.

18 of 19

Thanks!

QA Time!

19 of 19

Sample Code

  • You can find the sample code used in this presentation in the following Github repository