Book Review: Learning Android by Marko Gargenta (O'Reilly Book)

From Ittichai Chammavanijakul's Wiki
Jump to navigation Jump to search

Learning Android (http://ofps.oreilly.com/titles/9781449390501/index.html) by Marko Gargenta O'Reilly Books

Chapter 1: Android Overview

Chapter 2: The Stack

  • Android stacks
    • Linux kernel (display, camera, keypad, etc.)
    • Native libraries (Android runtime (CoreLibs, Delvik VM), OpenGL, SSL, SQLite, Webkit, etc.)
    • Application framework (Activity Manager, Content providers, Notification manager, etc.
    • Applications (Home, Contacts, Phone, Browser, etc.)
  • GNU libc, the default C library for Linux which Android is using, is licensed under GPL license, which requires any changes we release to be pushed back to the open source community. On the other hand, Android and some third-party open source libraries are licensed under an Apache/MIT license, which does not require derivative works to be open-sourced.
  • Dalvik is a purpose-built virtual machine designed specifically for Android, developed by Dan Bornstein and his team at Google.
  • While Java language, Java tools and Java libraries are free, the Java VM is not. Dalvik VM in Android is to replace the Java VM.
  • Differences between Android and Java
    • Java source code => (Java compiler) => Java byte code (running on Java VM).
    • Java source code => (Java compiler) => Java byte code => (Dex compiler) => Dalvik byte code => Dalvik executable (running on Dalvik VM).
  • Android Java is a nonstandard collection of Java classses. Its set of libraries is closet to Java Standard Edition.
  • The APK is a single application package file. It has three main components:
    • Dalvik executable = compiled code to executable
    • Resources = non-code - images, audio, etc.
    • Native libraries (optional) = some native code if any.

Chapter 3: Quick Start

  • Android SDK download page - http://developer.android.com/sdk
  • Installing the SDK http://developer.android.com/sdk/installing.html
  • Installing Eclipse http://eclipse.org/ - Eclipse IDE for Java Developers (not the twice-as-large Eclipse for Java EE Developers) is recommended.
  • Project files:
    • Manifest file has all application's main building blocks, what permission is required to run.
    • Layout XML code files specify the layout of the screen.
    • Strings (another XML file) contains all texts that application uses.
    • The R file is the glue between the Java and resources. It's automatically generated file.
    • Java source code contains all codes which will be converted to a Dalvik executable.
  • Emulator
    • Android SDK ships with a true emulator based on QEMU.

Chapter 4: Main Building Blocks

  • An Activity is usually a single screen on the device.
  • Activity Life Cycle
    • Launching an activity is expensive.
    • Transition from the Starting state to Running state is the most expensive.
    • The Running State is when one running activity is in focus.
    • The Paused state is when an activity is not in focus - showing dialog boxes
    • The Stopped state is when an activity is not visible, but still in memory (just in case if user might get back to it, restarting the Stopped activity is far cheaper then starting from scratch.
    • The Destroyed state is when the destroyed activity is no longer in memory.
  • Intents
    • The Intents are messages that are communicated among building blocks.
  • Services
    • Services run in the background, and can perform the same actions as the activities, but they don't have any user interfaces.
  • Content Providers
    • They are interfaces for sharing data between applications.
    • The Content Provider API adheres to the CRUD principle http://en.wikipedia.org/wiki/Create,_read,_update_and_delete.
    • For example, the Contacts Provider is a content provider that exposes all user contact data to other applications. The Contacts app itself does not have any contacts data, and Contacts Provider does not have any user interface.
  • Broadcast Receivers
    • Broadcast Receivers are using the publish/subscribe mechanism (or Observer pattern).
    • System sends broadcast events all the time, e.g., when an SMS arrives, or when it reboots, etc.
    • Broadcast Receivers do not have any user interfaces, nor are they actively running in memory. When triggered, they will execute some codes such as starting an activity, or a service.
  • Application Context
    • Application Context refers to the application environment and the processes within which all its components (activity, service, content provider, and broadcast receiver) are running. It allows applications to shared data and resources among components.
    • An application Context is created whenever the first component of this application is started up.

Chapter 5: Yamba Project Overview

  • Design Philosophy
    • Small increments
    • Always whole and complete
    • Refactoring code

Chapter 6: Android User Interface

  • Two ways to create a user interface
    • Declarative User Interface using XML - WYSIWYG
    • Programmatic User Interface using Java code
    • Best practice is to use both methods.
  • Views and Layouts
    • Views - button, label, text box, and so on. This sometime is called Widget (not App Widget).
    • Layouts organize views (grouping, location)
      • LinearLayout - simplest, layout_orientation (vertical or horizontal)
      • TableLayout
      • FrameLayout
      • RelativeLayout can minimize the total number of views, thus improving performance
      • AbsoluteLayout
  • Important Widget properties
    • layout_height and layout_width
        • fill_parent - widget wants all available space fro its parent
        • wrap_content - widget requires only as much space as it needs to display its own content
        • In the API level 8 or higher, the fill_parent has been renamed to match_parent.
    • layout_weight - a number between 0 and 1
    • layout_gravity - top, center, left, and so on
    • gravity - the content of the widget withing the widget itself
    • text - best practice is to use the pre-defined text in the string.xml
    • id - unique identifier

Chapter 7: Preferences, the Filesystem, the Options Menu, and Intents

  • Preferences
    • Create a Preference resource files called prefs.xml.
    • Implement the PrefsActivity.java file that inflates that resource file.
    • Register this new activity with the AndroidManifest.xml file.
    • Provide a way to start that activity from the rest of the application.
  • The Options Menu
    • Create the menu.xml resource where we specify what the menu consists of.
    • Add onCreateOptionsMenu() to the activity that should have this menu.
    • Provide handling of menu events in onOptionsItemSelected().

Chapter 8: Services

Chapter 9: The Database

Chapter 10: Lists and Adapters

Chapter 11: Broadcast Receivers

Chapter 12: Content Providers

Chapter 13: System Services

Chapter 14: The Android Interface Definition Language

Chapter 15: The Native Development Kit (NDK)