Skip to content

Latest commit

 

History

History
 
 

android

Getting Started

The Fast Track

  1. Read through the Introduction to Android (it's very high signal and starts to point you to good initial resources).
  • You'll install Android Studio: IntelliJ configured for Android development.
  • Prime with Building Your First App, ASAP.
  • Get familiar with the two primary app components: Activities and Fragments.
    • pay special attention to the lifecycle stuff.
  • Go through the Android Testing Codelab to get a feel for how TDD can look on Android.
  • (TODO: Dagger 2)

Installing Android Studio

Summary

  • Pivotal machine images come with Java 6. Uninstall that and install Oracle's Java before you install Android Studio.
  • When installing Android SDKs use the SDK manager from within Android Studio (because they told you to) and first expand a given SDK level and install everything from that level.
  • Get a local copy of the developer docs: Preferences ... Android SDK > SDK Tools > Documentaton for Android SDK

Install Sessions:

Fundamentals

Application Architecture

The Things

  • Activities encapsulate a single screen of interaction with the user.
    • which are composed from UI chunks or Fragments.
  • Intents are messages sent to Activites, Services, and Broadcast Receivers. Intents are messages sent between "application components".
    • the payload of an Intent is an "Action", "Category" and "Extras".
    • invoking Activities can request a response (which arrives in the form of an Intent)
  • Services encapsulate "backend" behavior that requires no UI.
  • Broadcast Receivers responses to system-wide events (via an Intent).
  • Content Providers encapsulate a data store meant to be shared with other applications (e.g. Contacts).
  • App Widgets are mini applications that are meant to be used within another application (e.g. mini music player on the Home screen).

Process and Thread Model

Scheduling / Lifecycle

  • Each application begins as a process and a single thread.
  • Processes are kept alive as long as possible, but are terminated, least important to most.
  • The priorities are this (most to least):
    1. activities, services, and broadcast receivers that are actively doing work.
    • activities that are paused but still visible (or services bound to such activities)
    • background services (i.e. launched with startService())
    • backgrounded activities (i.e. that have been onStop()'ed.
  • Practical implication: a process doing the same work through a Service will be higher priority than a process using an async task.

Multi-Threading

  • Only do work within the UI thread when it costs less to do than spawning a new thread.
  • Use AsyncTask to background work efficiently.
    • fully featured. Allows you to report progress and be cancelled.
  • Work invoked through bound services occur not in the UI thread but from an OS-managed thread pool.
  • ContentProviders process requests in within its own process (and therefore its own thread pool)

General Attitudes

  • Android is an object-oriented system, designed to support lots of little things signaling to each other.
  • Design applications to operate as cooperating cells.
  • Individual components (Activities, Fragments, Services, etc.) must be resilient — design to survive sudden stops and restarts (e.g. when a user rotates the device).
  • AndroidManifest.xml is a public API of your "app"
  • Activities and Broadcast Receivers should have very quick transaction times; anything longer should become a Service.

Implementation Guidelines

The Activity Lifecycle

  • onCreate() — allocate resources, start fetches,
  • onStart()
  • onRestoreInstanceState() — restore UI and local app state
  • onResume()
  • onPause() — store data that should be persisted across application launches or that might be used by an Activity taking over.
  • onSaveInstanceState() — save local app state (not called if app is definitely quitting)
  • onStop()
    • cancel any background tasks (e.g. AsyncTask instances)
  • onDestroy()

The Activity Lifecycle

The Fragment Lifecycle

Out-of-The Box:

  • Most Views can save their own state (and will do so via the default implementation of Activity.onSaveInstanceState()).

    Tip: only widgets with an android:id will be saved.

Visual Aspects

  • sizing dimensions:
    • dp — (go-to) density-independent pixels; 1 dp = 1/160 th of the screen.
    • sp — (for text) dp's that are sensitive to user's scaling; all text should be in sp's.
    • mm, pt, in — useless as not all devices can scale these appropriately.