codestrong 2012 breakout session android internals and best practices

17
Titanium Mobile: Best Practices for Android Josh Roesslein, Software Engineer Appcelerator, Inc. [email protected] Max Stepanov, Senior Software Engineer Appcelerator, Inc. [email protected]

Upload: appcelerator-inc

Post on 09-May-2015

744 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Codestrong 2012 breakout session   android internals and best practices

Titanium Mobile:Best Practices for Android

Josh Roesslein, Software EngineerAppcelerator, Inc.

[email protected]

Max Stepanov, Senior Software EngineerAppcelerator, Inc.

[email protected]

Page 2: Codestrong 2012 breakout session   android internals and best practices

• History

• Windows and Navigation

• Layout events

• Event Bubbling

• Modern Look and Feel

• Debugging

Agenda

Page 3: Codestrong 2012 breakout session   android internals and best practices

• 0.8: HTML UI / WebView

• 0.9: Native UI / Mozilla Rhino

• 1.8: Google V8

History

Page 4: Codestrong 2012 breakout session   android internals and best practices

• Heavyweight vs. Lightweight

• Activities and Back Stack

• Back Stack

Windows and Navigation

Page 5: Codestrong 2012 breakout session   android internals and best practices

Windows and Navigation

Activity A

Activity B

Activity B

Window A

Window B

Window B

Window D

Page 6: Codestrong 2012 breakout session   android internals and best practices

• Eventing: Use postlayout NOT open

• A layout pass may not have occurred by the time an open event is fired

• A postlayout event occurs after a native Android layout pass (may occur multiple times)

Layouts

Page 7: Codestrong 2012 breakout session   android internals and best practices

• SDK 3.0 allows control over event bubbling

• Titanium.Event object has two new properties• bubbles• cancelBubble

• Current defaults are identical to 2.X, but will change to achieve parity in the future

Event bubbling

Page 8: Codestrong 2012 breakout session   android internals and best practices

Allow custom events to bubble

Allow bubbling to cancel during event handling

Control bubbling

view.addEventListener(“myEvent”, function(e) { e.cancelBubble = true; })

button.fireEvent(“myEvent”, {bubbles: true});

Page 9: Codestrong 2012 breakout session   android internals and best practices

Allow views to bubble up / not to bubble up events

For more information:

http://docs.appcelerator.com/titanium/3.0/index.html#!/guide/Event_Handling

Cancel bubbling

view.bubbleParent = false;

Page 10: Codestrong 2012 breakout session   android internals and best practices

• Target API level• Backwards

compatible• Unlocks newer

behaviors and features

• Themes• Consistent• Holo themes

• ActionBar• MenuItem

• Action Items• Tabs

• Opt-in• TabGroup API

Newer Look/Feel

tiapp.xml

<android xmlns:android=“…”> <manifest> <uses-sdk android:minSdkVersion=”8” android:targetSdkVersion="16"/> </manifest></android>

platform/android/res/values-v11/theme.xml

<resources> <style name="Theme.Titanium" parent="android:Theme.Holo.Light" /></resources>

New MenuItem Properties for ActionBar

win.activity.onCreateOptionsMenu = function(e) { var item = e.menu.add({ title: "Share" }); item.showAsAction = Ti.Android.SHOW_AS_ACTION_ALWAYS; // etc.};

Page 11: Codestrong 2012 breakout session   android internals and best practices
Page 12: Codestrong 2012 breakout session   android internals and best practices

Android Debugging

Page 13: Codestrong 2012 breakout session   android internals and best practices

Android Emulator Physical Devices

New in Titanium

Titanium 3.0Titanium 1.7

Page 14: Codestrong 2012 breakout session   android internals and best practices

• V8 only (for on-device debugging)

• Just plug in device into USB

• Launches faster than Emulator!

Device Debugging

Page 15: Codestrong 2012 breakout session   android internals and best practices

• UI thread for handling user interactions

• JS thread for the application logic

• Debugger thread for communications with Titanium Studio

• Other Android platform threads

Threading UI JS

User taps button 1

postlayout event

Geo location Function

EventListener 1 var x = 1;Ti.API.log(x);openWin(x);

EventListener 2 Line 1

Line 2Line 3

DBG

Run

Page 16: Codestrong 2012 breakout session   android internals and best practices

• Use conditional breakpoints

• JavaScript code block

• Hit count

• Use Console logging with Ti.API functions

Best Practices