Começando com Android

926 views

Published on

Palestra apresentada por Ivan de Aguirre no AndroidDay 2013.

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
926
On SlideShare
0
From Embeds
0
Number of Embeds
83
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Começando com Android

  1. 1. Começando com Android Ivan de Aguirre @IvAguirre ivan.aguirre@dextra-sw.com
  2. 2. Agenda • Parte1: o • Fragmentação. o Aplicações Nativas ou Híbridas? o Interface o Android 4.3 Parte2: o Como o Android gerencia recursos o Threading o Memory leaks
  3. 3. Fragmentação
  4. 4. Fragmentação - níveis de API 4.0.3 - 4.0.4 API 15 Ice Cream Sandwich
  5. 5. Fragmentação - níveis de API 4.1 - API 16 4.2 - API 17 4.3 - API 18 Jelly Bean
  6. 6. Fragmentação - níveis de API android:minSDKVersion
  7. 7. Fragmentação - níveis de API http://developer.android.com/about/ dashboards/index.html#Platform
  8. 8. Fragmentação - níveis de API Google Play Developer Console
  9. 9. Fragmentação - níveis de API android:minSDKVersion=”10”
  10. 10. Fragmentação - níveis de API android:minSDKVersion=”10” Android Support Library
  11. 11. Fragmentação - tela OpenSignal http://opensignal.com/reports/ fragmentation-2013/
  12. 12. http://opensignal.com/reports/fragmentation-2013/
  13. 13. Fragmentação - tela - Screen Size small, normal, large, xlarge, sw600dp, w1024dp, h720dp, ...
  14. 14. Fragmentação - tela - Density dpi = dots per inch (ldpi, mdpi, hdpi, xhdpi) dp = density-independent pixel sp = scale-independent pixel wrap_content match_parent
  15. 15. <Button android:id="@+id/btn_ok" android:layout_width="match_parent" android:layout_height="100dp" android:text="@android:string/ok" />
  16. 16. Aplicações Nativas X Híbridas Android, iOS, Windows Phone...
  17. 17. Aplicações Nativas X Híbridas Android, iOS, Windows Phone... Custo-benefício de três aplicações > Custo de uma aplicação híbrida ?
  18. 18. Aplicações Nativas X Híbridas Aplicações Nativas X Aplicações Híbridas: código nativo + + JavaScript
  19. 19. Aplicações Nativas X Híbridas “You can write amazing Web 2.0 and Ajax apps that look exactly and behave exactly like apps on the iPhone. (...) And guess what? There’s no SDK that you need! You’ve got everything you need if you know how to write apps using the most modern web standards to write amazing apps for the iPhone today. So developers, we think we’ve got a very sweet story for you. You can begin building your iPhone apps today.” Steve Jobs, 2007
  20. 20. Aplicações Nativas X Híbridas “You can write amazing Web 2.0 and Ajax apps that look exactly and behave exactly like apps on the iPhone. (...) And guess what? There’s no SDK that you need! You’ve Só que não… got everything you need if you know how to write apps using the most modern web standards to write amazing apps for the iPhone today. So developers, we think we’ve got a very sweet story for you. You can begin building your iPhone apps today.” Steve Jobs, 2007
  21. 21. Aplicações Nativas X Híbridas Martin Fowler, Developing Software for Multiple Mobile Devices. http://martinfowler.com/articles/multiMobile/
  22. 22. Aplicações Nativas X Híbridas Martin Fowler, Developing Software for Multiple Mobile Devices. http://martinfowler.com/articles/multiMobile/ “but cross-platform failed for desktop, so why should we expect it to succeed for mobile?”
  23. 23. Aplicações Nativas X Híbridas Martin Fowler, Developing Software for Multiple Mobile Devices. http://martinfowler.com/articles/multiMobile/ “but cross-platform failed for desktop, so why should we expect it to succeed for mobile?” “To translate to all platforms, you can only use what all platforms support - which means you can only use a subset of each platform's behavior.”
  24. 24. Aplicações Nativas X Híbridas Martin Fowler, Developing Software for Multiple Mobile Devices. http://martinfowler.com/articles/multiMobile/ “but cross-platform failed for desktop, so why should we expect it to succeed for mobile?” “To translate to all platforms, you can only use what all platforms support - which means you can only use a subset of each platform's behavior.” “...UI translation leads you to... The Uncanny Valley”
  25. 25. Aplicações Nativas X Híbridas “Javascript is too slow for mobile app use in 2013 (e.g., for photo editing etc.). It’s slower than native code by about 5...“ http://sealedabstract.com/rants/whymobile-web-apps-are-slow/
  26. 26. Aplicações Nativas X Híbridas Se sua aplicação mobile for um diferencial para o seu negócio considere fazer nativa.
  27. 27. Aplicações Nativas X Híbridas Que tal site web otimizado para mobile, que execute no Browser?
  28. 28. Interfaces http://developer.android.com/design
  29. 29. Android 4.3 • Bluetooth Low Energy (Smart Ready). • Media DRM. • Interfaces Java para OpenGL ES 3.0. • Android key store. • Hardware credential storage.
  30. 30. Parte 2 Algumas boas práticas. Sim... vamos ver um pouco de código agora :)
  31. 31. Gerência de Recursos 0 100% A B C
  32. 32. Gerência de Recursos 0 100% B C
  33. 33. Gerência de Recursos 0 100% B C D
  34. 34. Gerência de Recursos 0 100% C D
  35. 35. Gerência de Recursos 0 100% C D A
  36. 36. Gerência de Recursos Activity: onSaveInstanceState(Bundle state) onRestoreInstanceState(Bundle state) onCreate(Bundle state)
  37. 37. Gerência de Recursos Fragment: onSaveInstanceState(Bundle state) setRetainInstance(boolean retain) onCreate(Bundle state) onCreateView(LayoutInflater inflater ,ViewGroup group, Bundle state) onActivityCreated(Bundle state)
  38. 38. Gerência de Recursos onCreate onStart onResume
  39. 39. Gerência de Recursos onCreate onStart onResume
  40. 40. Gerência de Recursos onCreate onStart onResume onSaveInstanceState onPause onStop onDestroy
  41. 41. Gerência de Recursos onCreate onStart onResume onSaveInstanceState onPause onStop onDestroy onCreate onStart onResume
  42. 42. Gerência de Recursos onCreate onStart onResume onSaveInstanceState onPause onStop State onDestroy onCreate onStart onResume
  43. 43. Thread de UI paint onClick paint paint onReceive onItemSelected paint onPause onStop paint onDestroy
  44. 44. Thread de UI paint onClick paint paint onReceive onItemSelected paint onPause onStop paint onDestroy ANR
  45. 45. Thread de UI paint onClick paint paint onReceive onItemSelected paint onPause onStop paint onDestroy
  46. 46. Thread de UI paint onClick paint paint onReceive onItemSelected paint onPause onStop paint onDestroy Worker Thread
  47. 47. Thread de UI paint onClick paint paint onReceive onItemSelected paint onPause onStop paint onDestroy Worker Thread
  48. 48. Threading AsyncTask
  49. 49. Threading public class Activity { public void onCreate(Bundle savedInstance) { ... DownloadTask task = new DownloadTask(); task.execute(); ... } }
  50. 50. Threading Loader
  51. 51. Threading AsyncQueryHandler IntentService Handler java.lang.Thread #sqn
  52. 52. Sincronização SyncAdapter GCM Polling
  53. 53. Memory Leaks http://www.curious-creature.org/ 2008/12/18/avoid-memory-leaks-onandroid/ Romain Guy, 2008
  54. 54. Memory Leak - Problema public class Util { private Context context; private static Util singleton; public static Util get(Context context) { if (singleton == null) { this.singleton = new Util(context); } return singleton; } public String getHello() { return context.getString(R.string.hello); } }
  55. 55. Memory Leak - Problema public class MyActivity extends Activity { public void onCreate(Bundle savedInstance) { ... Util util = Util.get(this); String hello = util.getHello(); ... }
  56. 56. Memory Leak - Solução 1 public static Util get(Context context) { if (singleton == null) { Context ctx = context .getApplicationContext(); this.singleton = new Util(ctx); } return singleton; }
  57. 57. Memory Leak - Solução 2 public class Util { public static String getHello(Context ctx) { return ctx.getString( R.string.hello); } }
  58. 58. Memory Leak - Solução 2 public class MyActivity { public void onCreate(Bundle savedInstance) { ... String hello = Util.getHello(this); ... } }
  59. 59. Perguntas?
  60. 60. Muito Obrigado! Ivan de Aguirre @IvAguirre ivan.aguirre@dextra-sw.com

×