![Page 1: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/1.jpg)
Titanium Mobile:Best Practices for Android
Josh Roesslein, Software EngineerAppcelerator, Inc.
Max Stepanov, Senior Software EngineerAppcelerator, Inc.
![Page 2: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/2.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/3.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/4.jpg)
• Heavyweight vs. Lightweight
• Activities and Back Stack
• Back Stack
Windows and Navigation
![Page 5: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/6.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/7.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/9.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/10.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/11.jpg)
![Page 12: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/12.jpg)
Android Debugging
![Page 13: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/13.jpg)
Android Emulator Physical Devices
New in Titanium
Titanium 3.0Titanium 1.7
![Page 14: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/14.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/15.jpg)
• 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](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/16.jpg)
• Use conditional breakpoints
• JavaScript code block
• Hit count
• Use Console logging with Ti.API functions
Best Practices
![Page 17: Codestrong 2012 breakout session android internals and best practices](https://reader034.vdocuments.us/reader034/viewer/2022052410/554d17b8b4c905d4568b55bb/html5/thumbnails/17.jpg)
Josh Roesslein & Max Stepanov