Introdução ao desenvolvimento Android - Notas Soltas

  • 822 views
Uploaded on

Com mais de 200 milhões de dispositivos e com 700 mil novos dispositivos ativados diariamente, o Android é a plataforma móvel que promete uma democratização do mercado móvel no mundo. …

Com mais de 200 milhões de dispositivos e com 700 mil novos dispositivos ativados diariamente, o Android é a plataforma móvel que promete uma democratização do mercado móvel no mundo.

Esta nota tem como objetivo apresentar a plataforma Android a quem tem curiosidade de começar a desenvolver para estes dispositivos.

www.notassoltas.com

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
822
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
16
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. Introdução ao desenvolvimento em Android by Tiago BritoSunday, February 5, 12
  • 2. Me Tiago Brito • Software developer @ be.ubi • PHP | Symfony | Doctrine | mySQL | jQuery | git • Android programmer since 2009Sunday, February 5, 12
  • 3. Apps VATCheckerSunday, February 5, 12
  • 4. Apps Dicionário VATCheckerSunday, February 5, 12
  • 5. Apps Dicionário VATChecker Jogos de ApostasSunday, February 5, 12
  • 6. Apps Dicionário VATChecker Jogos de Movies ApostasSunday, February 5, 12
  • 7. Apps Dicionário VATChecker Jogos de Movies Trânsito ApostasSunday, February 5, 12
  • 8. Apps Dicionário VATChecker Cultura Jogos de Movies Trânsito ApostasSunday, February 5, 12
  • 9. Apps Dicionário VATChecker Cultura CCilhavo Jogos de Movies Trânsito ApostasSunday, February 5, 12
  • 10. Apps Dicionário VATChecker Cultura CCilhavo Jogos de Movies Trânsito Apostas HoróscopoSunday, February 5, 12
  • 11. Apps Dicionário Sinónimos VATChecker Cultura CCilhavo Jogos de Movies Trânsito Apostas HoróscopoSunday, February 5, 12
  • 12. Apps Portagens Dicionário Sinónimos VATChecker Cultura CCilhavo Jogos de Movies Trânsito Apostas HoróscopoSunday, February 5, 12
  • 13. Apps From: xxxxx xxxx@priberam.pt CC: DirecçãoJurídica <DireccaoJuridica@priberam.pt> Bom dia,   Verificámos que têm no Android Market uma aplicação que utiliza o conteúdo do Dicionário Priberam da Língua Portuguesa sem autorização da Priberam nem qualquer referência à proveniência do conteúdo.   Por essa razão e porque a Priberam disponibilizou uma aplicação sua para o Android de acesso ao Dicionário, vimos por este meio pedir-vos que retirem a aplicação do Android Market imediatamente.   Muito obrigado,   xxx xxxxx PriberamSunday, February 5, 12
  • 14. PetiscosSunday, February 5, 12
  • 15. TrânsitoSunday, February 5, 12
  • 16. Smart-lamp git rep: https://github.com/casainho/smart-lampSunday, February 5, 12
  • 17. Smart-lamp git rep: https://github.com/casainho/smart-lampSunday, February 5, 12
  • 18. Design tips • Always try to predict the user text. • Use the default interface • New input paradigm. Fingers ≠ mouse • Size of text. Distance to computer screen ≠ distance to mobile device. • Visual InformationSunday, February 5, 12
  • 19. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 20. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 21. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 22. Target Your App Serious content Entertainment Tool Fun Serious Tool •Productivity Type usage •Minimal UI •Create, modify, archieveSunday, February 5, 12
  • 23. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 24. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 25. Target Your App Serious content Entertainment Tool Fun Fun Tool • Fun to use and useful usage • Some graphically rich elements • Small information hierarchySunday, February 5, 12
  • 26. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 27. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 28. Target Your App Serious content Entertainment Tool Serious Entertainment Fun • No Productivity • Educacional entertainment usage • Data driven • Potentially hierarchicalSunday, February 5, 12
  • 29. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 30. Target Your App Serious content Entertainment Tool Fun usageSunday, February 5, 12
  • 31. Target Your App Serious content Entertainment Tool Fun Utilities • Rich Graphics usage • Single Screen • Ag in app 30 to 60sSunday, February 5, 12
  • 32. Dalvik.equals(Java) == false • The VM runs on top of a Linux 2.6 kernel. • A tool called dx is used to convert some (but not all) Java .class files into the .dex format. Multiple classes are included in a single .dex file. Duplicate strings and other constants used in multiple class files are included only once in the .dex output to conserve space. Java bytecode is also converted into an alternative instruction set used by the Dalvik VM. • JavaVM’s one can find on almost any desktop computer nowadays are Stack-based Virtual Machines (VM).The DalvikVM on the other hand is register based, because on mobile- processors are optimized for register- based execution. Also of register-based VMs allow faster execution times at the expense of programs which are larger after compilation.Sunday, February 5, 12
  • 33. Dalvik.equals(Java) == falseSunday, February 5, 12
  • 34. Anatomy of an Android Application • Activity • Intent Receiver • Service • Content ProviderSunday, February 5, 12
  • 35. Activity • An activity is usually a single screen in your application • One activity is designated as the entry point point for your applicationSunday, February 5, 12
  • 36. Activity LifecycleSunday, February 5, 12
  • 37. Activity public class NotasSoltasActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); }Sunday, February 5, 12
  • 38. Service A Service is code that is long-lived and runs without a UI. A good example of this is a media player playing songs from a play list.Sunday, February 5, 12
  • 39. Intents Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. For example an Activity can send an Intents to the Android system which starts another Activity.Sunday, February 5, 12
  • 40. Content Provider Applications can store their data in files, a SQLite database, preferences or any other mechanism that makes sense. A content provider, however, is useful if you want your applications data to be shared with other applications. A content provider is a class that implements a standard set of methods to let other applications store and retrieve the type of data that is handled by that content provider.Sunday, February 5, 12
  • 41. AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.inovadoor.android.petiscos" android:versionCode="9" android:versionName="1.4.2"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false"> <activity android:name=".Main" android:label="@string/app_name" android:launchMode="singleTop" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> <activity android:name="CategoriasListActivity" android:configChanges="orientation|keyboardHidden"></activity> <activity android:name="ReceitaDetailsActivity" android:configChanges="orientation|keyboardHidden" ></activity> <activity android:name="ReceitasListActivity" android:configChanges="orientation|keyboardHidden"></activity> <activity android:name="SimpleReceitasListActivity" android:configChanges="orientation|keyboardHidden" ></activity> <activity android:name=".PreferencesActivity" android:label="@string/prefsTitle" android:configChanges="orientation|keyboardHidden"> </activity> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" /> </manifest>Sunday, February 5, 12
  • 42. MVC Controler Model ViewSunday, February 5, 12
  • 43. Development Tools • Eclipse plugin • Android SDKSunday, February 5, 12
  • 44. Development Tools Emulator Simulator The difference between emulators and simulators is that emulators mimic the software and hardware environments found on actual devices. Simulators, on the other hand, only mimic the software environment.Sunday, February 5, 12
  • 45. Project MyProject/ src/ MyActivity.java res/ drawable/ icon.png layout/ main.xml info.xml values/ strings.xml values-pt/ strings.xmlSunday, February 5, 12
  • 46. Common ProblemsSunday, February 5, 12
  • 47. Common Problems • ANR (App Not Responding) block main thread for more than 5 seconds • Manifest missing configurationsSunday, February 5, 12
  • 48. Common Problems Don’t block the main threadSunday, February 5, 12
  • 49. Common Problems Don’t block the main thread public void onClick(View v) {   new Thread(new Runnable() {     public void run() {       Bitmap b = loadImageFromNetwork();       mImageView.setImageBitmap(b);     }   }).start(); }Sunday, February 5, 12
  • 50. Common Problems Don’t block the main thread public void onClick(View v) {   new Thread(new Runnable() {     public void run() {       Bitmap b = loadImageFromNetwork();       mImageView.setImageBitmap(b);     }   }).start(); } public void onClick(View v) {   new Thread(new Runnable() {     public void run() {       final Bitmap b = loadImageFromNetwork();       mImageView.post(new Runnable() {         public void run() {           mImageView.setImageBitmap(b);         }       });     }   }).start(); }Sunday, February 5, 12
  • 51. Common Problems public void onClick(View v) {   new DownloadImageTask().execute("http://example.com/image.png"); } private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {      protected Bitmap doInBackground(String... urls) {          return loadImageFromNetwork(urls[0]);      }      protected void onPostExecute(Bitmap result) {          mImageView.setImageBitmap(result);      }  }Sunday, February 5, 12
  • 52. Performance • Avoid Creating Unnecessary Objects • Avoid Internal Getters/Setters In native languages like C++ its common practice to use getters (e.g. i = getCount()) instead of accessing the field directly (i = mCount). This is an excellent habit for C++, because the compiler can usually inline the access, and if you need to restrict or debug field access you can add the code at any time. On Android, this is a bad idea.Virtual method calls are expensive, much more so than instance field lookups. Its reasonable to follow common object-oriented programming practices and have getters and setters in the public interface, but within a class you should always access fields directly. • Prefer Static Over Virtual If you dont need to access an objects fields, make your method static. Invocations will be about 15%-20% faster.Sunday, February 5, 12
  • 53. Performance • Use Enhanced For Loop Syntax static class Foo {         int mSplat;     }     Foo[] mArray = ...     public void one() {         int sum = 0;     public void zero() {         Foo[] localArray = mArray;         int sum = 0;         int len = localArray.length;         for (int i = 0; i < mArray.length; ++i) {             sum += mArray[i].mSplat;        for (int i = 0; i < len; ++i) {         }            sum += localArray[i].mSplat;     }        }     }     public void two() {         int sum = 0;         for (Foo a : mArray) {             sum += a.mSplat;         }     }Sunday, February 5, 12
  • 54. Performance RecyclerSunday, February 5, 12
  • 55. Web app VS Native • If you are building a native app, make sure, that it will be amazing. • PhoneGap - http://phonegap.com/ PhoneGap is an HTML5 app platform that allows you to author native applications with web technologies and get access to APIs and app stores. PhoneGap leverages web technologies developers already know best... HTML and JavaScript.Sunday, February 5, 12
  • 56. Demo This slide has been deliberately left blankSunday, February 5, 12
  • 57. Android Market • 25$ registation fee for developers • 30 / 70Sunday, February 5, 12
  • 58. Android MarketSunday, February 5, 12
  • 59. Inspiration • What app should i make? • Identify a necessity • Forget Apps, build a service! • Use the out-of-the-box phone features: GPS, Contact List, Google Account, Internet, Accelerometer, MapsSunday, February 5, 12
  • 60. MarketSunday, February 5, 12
  • 61. Market • Right now, Portuguese market is too small for mobile ads revenue. • Take advantage of Portuguese language • Think Global.Sunday, February 5, 12
  • 62. Market • Right now, Portuguese market is too small for mobile ads revenue. • Take advantage of Portuguese language • Think Global.Sunday, February 5, 12
  • 63. Market “The latest Distimo report found that just two paid Android apps have ever eclipsed the half-million milestone, while six iPhone apps did that in two months in April and May.” “Overall, 79.3 percent of all paid Android apps have been downloaded less than 100 times, and only 4.6 percent of paid apps were downloaded more than 1,000 times.” http://gigaom.com/2011/05/27/android-still-trails-ios-as-a-money-maker-for-devs/Sunday, February 5, 12
  • 64. Fragmentation Trânsito Versão Utilizadores Android 2.3.3+ 1024 Android 1.6 3.1 4.0 Android 4.0.3 Android Android 2.2 763 Android 1.5 Android 2.3 Android 3.2 Android 4% 2%0% 1% 1% 0% 5% Android 2.1 500 Android 2.1 Android 1.5 123 19% Android 1.6 115 Android 2.3.3+ Android 3.1 41 39% Android 4.0.3 27 Android 2.3 14 Android 4.0 8 Android 2.2 29% Android 3.2 8 Android 2.3.3+ Android 2.2 Android 2.1 Android 1.5 Android 1.6 Android 3.1 Android 4.0.3 Android 2.3 Android 4.0 Android 3.2Sunday, February 5, 12
  • 65. Links • http://developer.android.com • https://market.android.com/publish • Dianne Hackborn • Andrew Munn • http://blog.crazybob.org/2011/12/truth-about- android-ios-ui-performance.htmlSunday, February 5, 12
  • 66. The end Tiago Brito tlfbrito@gmail.com @tlfbritoSunday, February 5, 12