Don Thorp & Marshall Culpepper: Advanced Titanium Development for Android

Preview:

DESCRIPTION

In this presentation, we will provide an overview of native Android tooling and some of its uses. We will also cover several Android specific concepts and APIs and discuss how you can use them when creating a best of breed application.Tooling- DDMS- adb (Android Debug Bridge)- android (Downloading SDKs, Managing AVDs)APIs- Android Lifecycle Events- Intents, Activities, Notifications- Javascript Activities- Resources- Android Section of tiapp.xml

Citation preview

Advanced  Titanium  Development  for  Android  

Don  Thorp  &  Marshall  Culpepper    

2 http://www.appcelerator.com | @appcelerator

Android Tooling

• Android Debug Bridge (adb) • DDMS (Dalvick Debug Monitor Server) • “android” • “hierarchyviewer” • “traceview”

3 http://www.appcelerator.com | @appcelerator

Android Debug Bridge (adb)

•  the swiss army knife of Android, tons of commands, works with emulator & device • push / pull: upload / download files •  install / uninstall applications •  shell: full /bin/sh system access •  logcat: app / device logging

4 http://www.appcelerator.com | @appcelerator

DDMS

• Graphical frontend to adb, and other android SDK tools • App process control • Colored Logcat output • Mock Geo / Phone call / etc control • Minimal memory / cpu profiling

5 http://www.appcelerator.com | @appcelerator

Other Android SDK Tools

•  “android” – manage virtual devices (emulators w/ versions, SDcard

size, etc) – SDK updates, extras

•  “hierarchyviewer”: – Layout / UI debugging tool

•  “traceview” – Visual call hierarchy / CPU profiling

• Much more, See the official Android docs (links at the end)

6 http://www.appcelerator.com | @appcelerator

Android Concepts •  Application – Collection of one or more Activities • Selected by OS w/ Intent filters

– SDK version compatibility (API Level)

•  Intent

– Fully serializable data, used between Activities – Various fields/options • Action (VIEW, EDIT, SEND, etc), Data (URI) • Category (CATEGORY_LAUNCHER etc) • Mime type (e.g. vnd.android.cursor.item/phone) • Class name (e.g. com.mycompany.Activity) • Extra’s - Custom key/value pairs

7 http://www.appcelerator.com | @appcelerator

Android Concepts

• Activity –  Task Stack • Inter-app + screen navigation

–  App entry point –  Handle system+custom intents • Can return values to other activities

• Others –  Service –  Notifications, PendingIntent

8 http://www.appcelerator.com | @appcelerator

App/Activity Life Cycle

• User launches app – Intent is fired to app

with: • category: CATEGORY_LAUNCHER • action: MAIN

9 http://www.appcelerator.com | @appcelerator

How do I do that with Ti?

•  Custom JS Activities – JS Activities can be simple (launched via URL) or complex

(launched via intent filter from the system) – Configured via tiapp.xml

•  Everything else (mostly) follows a 1:1 mapping w/ official Android API – All constants / create* methods live in Ti.Android – i.e. Ti.Android.createIntent – Access current activity with Ti.Android.currentActivity – Activity.startActivityForResult supports a function

callback for convenience

10 http://www.appcelerator.com | @appcelerator

Resources

• Use Android density / orientation res specifiers in Resources/android/images • Arbitrary android native resources can live

in project’s platform/android

11 http://www.appcelerator.com | @appcelerator

tiapp.xml examples

12 http://www.appcelerator.com | @appcelerator

JS Examples

13 http://www.appcelerator.com | @appcelerator

Javascript Engines

• Rhino –  Our current Javascript Engine –  Java based which allows it to work on devices

without NDK support

• V8 –  Used in Chrome, Chromium, NodeJS, and more –  C++ based requires NDK support –  Performance 2X minimum, in many cases 10-15x

14 http://www.appcelerator.com | @appcelerator

Titanium+Android Demos

15 http://www.appcelerator.com | @appcelerator

Links!

• Android Tools: http://developer.android.com/guide/developing/tools/index.html •  Ti.Android module:

http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android-module •  Services in Titanium:

http://developer.appcelerator.com/doc/mobile/android-simple-services