66
Introdução ao desenvolvimento em Android by Tiago Brito Sunday, February 5, 12

Introdução ao desenvolvimento Android - Notas Soltas

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Introdução ao desenvolvimento Android - Notas Soltas

Introdução ao desenvolvimento em

Androidby Tiago Brito

Sunday, February 5, 12

Page 2: Introdução ao desenvolvimento Android - Notas Soltas

Me

Tiago Brito

• Software developer @ be.ubi

• PHP | Symfony | Doctrine | mySQL | jQuery | git

• Android programmer since 2009

Sunday, February 5, 12

Page 3: Introdução ao desenvolvimento Android - Notas Soltas

Apps

VATChecker

Sunday, February 5, 12

Page 4: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Dicionário

VATChecker

Sunday, February 5, 12

Page 5: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Dicionário

Jogos de Apostas

VATChecker

Sunday, February 5, 12

Page 6: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Movies

Dicionário

Jogos de Apostas

VATChecker

Sunday, February 5, 12

Page 7: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Movies Trânsito

Dicionário

Jogos de Apostas

VATChecker

Sunday, February 5, 12

Page 8: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Cultura

Movies Trânsito

Dicionário

Jogos de Apostas

VATChecker

Sunday, February 5, 12

Page 9: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Cultura

Movies Trânsito

Dicionário

CCilhavoJogos de Apostas

VATChecker

Sunday, February 5, 12

Page 10: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Cultura

Movies

Horóscopo

Trânsito

Dicionário

CCilhavoJogos de Apostas

VATChecker

Sunday, February 5, 12

Page 11: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Cultura

Movies

Horóscopo

Trânsito

Dicionário

CCilhavoJogos de Apostas

SinónimosVATChecker

Sunday, February 5, 12

Page 12: Introdução ao desenvolvimento Android - Notas Soltas

Apps

Portagens

Cultura

Movies

Horóscopo

Trânsito

Dicionário

CCilhavoJogos de Apostas

SinónimosVATChecker

Sunday, February 5, 12

Page 13: Introdução ao desenvolvimento Android - Notas Soltas

Apps

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 xxxxxPriberam

From: xxxxx [email protected]: DirecçãoJurídica <[email protected]>

Sunday, February 5, 12

Page 14: Introdução ao desenvolvimento Android - Notas Soltas

Petiscos

Sunday, February 5, 12

Page 15: Introdução ao desenvolvimento Android - Notas Soltas

Trânsito

Sunday, February 5, 12

Page 16: Introdução ao desenvolvimento Android - Notas Soltas

Smart-lampgit rep: https://github.com/casainho/smart-lamp

Sunday, February 5, 12

Page 17: Introdução ao desenvolvimento Android - Notas Soltas

Smart-lampgit rep: https://github.com/casainho/smart-lamp

Sunday, February 5, 12

Page 18: Introdução ao desenvolvimento Android - Notas Soltas

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 Information

Sunday, February 5, 12

Page 19: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageSunday, February 5, 12

Page 20: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageSunday, February 5, 12

Page 21: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usage

Sunday, February 5, 12

Page 22: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageSerious Tool

•Productivity Type•Minimal UI•Create, modify, archieve

Sunday, February 5, 12

Page 23: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageSunday, February 5, 12

Page 24: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usage

Sunday, February 5, 12

Page 25: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageFun Tool

• Fun to use and useful• Some graphically rich elements• Small information hierarchy

Sunday, February 5, 12

Page 26: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageSunday, February 5, 12

Page 27: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usage

Sunday, February 5, 12

Page 28: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usage

Serious Entertainment• No Productivity• Educacional entertainment• Data driven• Potentially hierarchical

Sunday, February 5, 12

Page 29: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageSunday, February 5, 12

Page 30: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usage

Sunday, February 5, 12

Page 31: Introdução ao desenvolvimento Android - Notas Soltas

Target Your AppSerious

Entertainment

Fun

Tool

content

usageUtilities

• Rich Graphics• Single Screen• Ag in app 30 to 60s

Sunday, February 5, 12

Page 32: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 33: Introdução ao desenvolvimento Android - Notas Soltas

Dalvik.equals(Java) == false

Sunday, February 5, 12

Page 34: Introdução ao desenvolvimento Android - Notas Soltas

Anatomy of an Android Application

• Activity

• Intent Receiver

• Service

• Content Provider

Sunday, February 5, 12

Page 35: Introdução ao desenvolvimento Android - Notas Soltas

Activity

• An activity is usually a single screen in your application

• One activity is designated as the entry point point for your application

Sunday, February 5, 12

Page 36: Introdução ao desenvolvimento Android - Notas Soltas

Activity Lifecycle

Sunday, February 5, 12

Page 37: Introdução ao desenvolvimento Android - Notas Soltas

Activitypublic 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(); }

@OverrideSunday, February 5, 12

Page 38: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 39: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 40: Introdução ao desenvolvimento Android - Notas Soltas

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 application's 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

Page 41: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 42: Introdução ao desenvolvimento Android - Notas Soltas

MVC

Model View

Controler

Sunday, February 5, 12

Page 43: Introdução ao desenvolvimento Android - Notas Soltas

Development Tools

• Eclipse plugin

• Android SDK

Sunday, February 5, 12

Page 44: Introdução ao desenvolvimento Android - Notas Soltas

Development ToolsEmulator 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

Page 45: Introdução ao desenvolvimento Android - Notas Soltas

Project

MyProject/ src/ MyActivity.java res/ drawable/ icon.png layout/ main.xml info.xml values/ strings.xml

values-pt/ strings.xml

Sunday, February 5, 12

Page 46: Introdução ao desenvolvimento Android - Notas Soltas

Common Problems

Sunday, February 5, 12

Page 47: Introdução ao desenvolvimento Android - Notas Soltas

Common Problems

• ANR (App Not Responding)block main thread for more than 5 seconds

• Manifest missing configurations

Sunday, February 5, 12

Page 48: Introdução ao desenvolvimento Android - Notas Soltas

Common ProblemsDon’t block the main thread

Sunday, February 5, 12

Page 49: Introdução ao desenvolvimento Android - Notas Soltas

Common Problems

public void onClick(View v) {  new Thread(new Runnable() {    public void run() {      Bitmap b = loadImageFromNetwork();      mImageView.setImageBitmap(b);    }  }).start();}

Don’t block the main thread

Sunday, February 5, 12

Page 50: Introdução ao desenvolvimento Android - Notas Soltas

Common Problems

public void onClick(View v) {  new Thread(new Runnable() {    public void run() {      Bitmap b = loadImageFromNetwork();      mImageView.setImageBitmap(b);    }  }).start();}

Don’t block the main thread

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

Page 51: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 52: Introdução ao desenvolvimento Android - Notas Soltas

Performance

• Avoid Creating Unnecessary Objects

• Avoid Internal Getters/SettersIn native languages like C++ it's 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. It's 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 VirtualIf you don't need to access an object's fields, make your method static. Invocations will be about 15%-20% faster.

Sunday, February 5, 12

Page 53: Introdução ao desenvolvimento Android - Notas Soltas

Performance• Use Enhanced For Loop Syntax

static class Foo {        int mSplat;    }    Foo[] mArray = ...

    public void zero() {        int sum = 0;        for (int i = 0; i < mArray.length; ++i) {            sum += mArray[i].mSplat;        }    }

    public void two() {        int sum = 0;        for (Foo a : mArray) {            sum += a.mSplat;        }    }

    public void one() {        int sum = 0;        Foo[] localArray = mArray;        int len = localArray.length;

        for (int i = 0; i < len; ++i) {            sum += localArray[i].mSplat;        }    }

Sunday, February 5, 12

Page 54: Introdução ao desenvolvimento Android - Notas Soltas

Performance

RecyclerSunday, February 5, 12

Page 55: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 56: Introdução ao desenvolvimento Android - Notas Soltas

Demo

This slide has been deliberately left blank

Sunday, February 5, 12

Page 57: Introdução ao desenvolvimento Android - Notas Soltas

Android Market• 25$ registation fee for developers

• 30 / 70

Sunday, February 5, 12

Page 58: Introdução ao desenvolvimento Android - Notas Soltas

Android Market

Sunday, February 5, 12

Page 59: Introdução ao desenvolvimento Android - Notas Soltas

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, Maps

Sunday, February 5, 12

Page 60: Introdução ao desenvolvimento Android - Notas Soltas

Market

Sunday, February 5, 12

Page 61: Introdução ao desenvolvimento Android - Notas Soltas

Market

• Right now, Portuguese market is too small for mobile ads revenue.

• Take advantage of Portuguese language

• Think Global.

Sunday, February 5, 12

Page 62: Introdução ao desenvolvimento Android - Notas Soltas

Market

• Right now, Portuguese market is too small for mobile ads revenue.

• Take advantage of Portuguese language

• Think Global.

Sunday, February 5, 12

Page 63: Introdução ao desenvolvimento Android - Notas Soltas

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

Page 64: Introdução ao desenvolvimento Android - Notas Soltas

Fragmentation

Android 3.20%

Android 4.00%

Android 2.31%

Android 4.0.31%

Android 3.12%

Android 1.64%Android 1.5

5%

Android 2.119%

Android 2.229%

Android 2.3.3+39%

Trânsito

Android 2.3.3+ Android 2.2 Android 2.1Android 1.5 Android 1.6 Android 3.1Android 4.0.3 Android 2.3 Android 4.0Android 3.2

Versão UtilizadoresAndroid 2.3.3+ 1024Android 2.2 763Android 2.1 500Android 1.5 123Android 1.6 115Android 3.1 41Android 4.0.3 27Android 2.3 14Android 4.0 8Android 3.2 8

Sunday, February 5, 12

Page 66: Introdução ao desenvolvimento Android - Notas Soltas

The end

Tiago Brito

[email protected]@tlfbrito

Sunday, February 5, 12