Skip to content

Instantly share code, notes, and snippets.

@dwayne
Last active December 29, 2019 03:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwayne/8648817 to your computer and use it in GitHub Desktop.
Save dwayne/8648817 to your computer and use it in GitHub Desktop.
Programming Mobile Applications for Android Handheld Systems Course Notes

Introduction to the Android Platform

Getting Started

The Android Architecture (bottom to top)

  • Linux Kernel
  • Libraries & Android Runtime
  • Application Framework
  • Applications

Typical Workflow

  • Application is written in Java
  • Compiled to Java bytecode files
  • DX converts Java bytecode files to a single dex bytecode file (classes.dex)
  • The dex file is packaged with other application resources and installed on the device
  • Dalvik VM executes the dex bytecode file

Dalvik VM Internals by Dan Bornstein

The Android Development Environment

The Android Development Environment is your workbench for creating Android applications. Like any skilled crafts person, the more comfortable you are with your tools the easier it's going to be to produce top quality work.

Resources

The Intent Class

An intent is an abstract description of an operation to be performed.

Intent Fields

  • Action
  • Data
  • Category
  • Type
  • Component
  • Extras
  • Flags

Resources

To learn/investigate more about Intent Filters look at the following command:

$ adb shell dumpsys package

Permissions

Android uses permissions to protect data, resources and operations.

Applications can also define and enforce their own permissions.

Resources

The Fragment Class

Fragments were added to Android in version 3.0 to better support user interfaces for devices with large screens such as tablets. They represent a portion of an activity's user interface. Fragments have a lifecycle which is coordinated with the lifecycle of its containing activity.

Configuration Changes

If you call setRetainInstance(true), Android won't destroy the fragment on configuration changes.

Resources

User Interface Classes

User Interface

Views

View Events

View Groups

View groups are invisible views that contain other views. The are used to group and organize multiple views and view groups.

Some example view groups:

Adapters and Adapter Views

Adapter views are view groups whose child views and underlying data are managed by another class called an adapter.

Layouts

Layouts are generic view groups that are used to organize and structure other views and view groups.

Menus

Action Bar

Dialogs

User Notifications

Notifications are messages that applications show to users outside the normal user interface of the application.

Two different kinds of user notifications that Android supports:

  1. Toasts
  2. Notification Area Notifications

For user feedback you can use:

For event notifications you can use:

Toast

Toast messages are temporary messages that pop-up on the display. They automatically fade in and fade out of view.

Notification Area Notifications

This kind of user notification appears in the system controlled area at the top of the device called the notification area or the status bar. Applications and the Android system itself can use this area to inform users about the occurrence of various events.

A pending intent is essentially a permission slip that allows one piece of code to stand in for another piece of code. This permission slip allows the second piece of code to activate the underlying intent as if it were the first piece of code, i.e. it does it with the permissions and identity of that first piece of code.

Broadcast Receivers

Typical use case:

  1. BroadcastReceivers register to receive specific intents.
  2. Some component generates an intent and then broadcasts it to the system.
  3. Android delivers that intent to the BroadcastReceiver's registered to receive it.
  4. The BroadcastReceivers then get a call to their onReceive() method during which they handle the incoming event.

BroadcastReceivers can register in two ways:

  1. Statically, in AndroidManaifest.xml.
  1. Dynamically, by calling a registerReceiver() method.

Intents can be broadcast normally or in-order. Normal broadcasts are delivered to subscribed BroadcastReceivers in an undefined order. Ordered broadcasts deliver the intent to multiple BroadcastReceivers one at a time in priority order.

Broadcasts can also be sticky or non-sticky. A sticky broadcast sticks around after its initial broadcast. Non-sticky broadcasts are discarded after their initial broadcast.

Some debugging tips

  • Log extra intent resolution information by setting Intent.setFlag(FLAG_DEBUG_LOG_RESOLUTION)
  • List registered BroadcastReceivers
    • Dynamically registered, $ adb shell dumpsys activity b
    • Statically registered, $ adb shell dumpsys package

Alarms

Alarms are a mechanism for sending intents at some point (or points) in the future. This is useful because it allows an application to cause some other code to execute, even when that application is no longer running. Once alarms have been created and registered they are retained and monitored even if the device goes to sleep.

Alarm examples

  • MMS - Retry scheduler
  • Settings - Bluetooth discoverable timeout
  • Phone - User info cache

Using Alarms

To use alarms you do so by interacting with the AlarmManager. You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.ALARM_SERVICE).

Graphics and Animation

Topics

2D Graphics

Draw to a view when:

  • Simple graphics
  • Little or no updates

Draw to a canvas when:

  • Complex graphics
  • Regular updates

The Drawable class represents things that can be drawn. For e.g. bitmaps, colors, shapes etc.

Drawing with a canvas, you will need:

  • A bitmap (a matrix of pixels)
  • A canvas for drawing to the underlying bitmap
  • A drawing primitive (e.g. rectangle, text, path, bitmap, etc.)
  • A paint object (for setting drawing colors and styles)

A surface view provides a dedicated drawing surface embedded inside of a view hierarchy.

View Animation

Property Animation

Resources

@dwayne
Copy link
Author

dwayne commented Feb 7, 2014

@dwayne
Copy link
Author

dwayne commented Mar 4, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment