Your SlideShare is downloading. ×

Best Practices in Mobile Development

2,593

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,593
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
44
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. WELCOME TO TITANIUM WEEK! Day Five: Titanium Mobile Best Practices Kevin Whinnery Boydlee Pollentine Rick Blalock
  • 2. Titanium Mobile Best Practices
  • 3. KEVIN WHINNERY DIRECTOR OFDEVELOPER RELATIONS APPCELERATOR
  • 4. Agenda • Architecture Principles • Resource management • Custom Components • Titanium Cookbook • Q&A
  • 5. Baseline Best Practices
  • 6. Titanium App Architecture• Titanium APIs are low level (not Obj-C low level, but still)• Common question is “how do I structure my app”?• MVC or MVVM is fine – Appc unlikely to adopt a high level framework here• More important – separation of concerns
  • 7. Separation of Concerns• You probably already know this, but…• Since Titanium is all JavaScript, it‟s easy to break• Generally, we have a few buckets: – UI Components (Construction and Behavior) – Services (Database, Network, Geolocation) – Model Objects
  • 8. Help organize this separation withCommonJS modules
  • 9. CommonJS Modules• Standard in the JavaScript community• Advantages over Ti.include and the “module pattern”: – Secure by default – Control public/private interface – No ungainly management of large JavaScript namespaces
  • 10. CommonJS Module Guide on theWiki: http://bit.ly/ti-modules-guide
  • 11. Obligatory TODO List
  • 12. TODO List Highlights• Component-oriented UI• Separation of concerns• Well-defined interfaces – What if I switched data stores? – As long as I maintain my data store interface, I can swap out the underlying implementation if I want
  • 13. Resource Management
  • 14. Typically, Memory Management
  • 15. When Does Titanium Clean Up?• Native UI that provides memory management (tabs, scrollable)• When windows are closed• When a reference to a proxy goes out of scope, and is garbage collected
  • 16. What does that mean for you?
  • 17. Weapons Against Leaks• When possible, use native UI components that intelligently manage memory• Closing windows will clean up associated UI resources• Forcing cleanup of unneeded objects
  • 18. Forcing Clean-Up/** Most of the time, this will do* the trick…*/var v = Ti.UI.createView();v = null;
  • 19. Forcing Clean-Up/** But don’t forget about* global listeners!*/var f = function() {…};Ti.App.addEventListener(‘foo’,f);Ti.App.removeEventListener(‘foo’,f);
  • 20. Custom Components
  • 21. Oversimplifying Proxy Objects• Ti.* objects are often “proxies” for native objects which do native stuff• When you say view.setBackgroundColor(), that triggers special magic in native land• Most of the time that‟s fine, but proxies don‟t „play by the rules‟ of JavaScript
  • 22. Extending Proxies• Often we want to „subclass‟ views like in the Todo list• Where we run into problems is adding members to proxies• If that becomes necessary, then we need to employ a wrapping JavaScript object
  • 23. Custom Component Wrapper
  • 24. …but more on that Friday.
  • 25. BOYDLEE POLLENTINE AUTHORAPPCELERATOR TITANIUM SMARTPHONE APP DEVELOPMENT COOKBOOK
  • 26. Any Questions?
  • 27. Thank You!

×