introdução ao desenvolvimento android - notas soltas
Post on 17-May-2015
872 Views
Preview:
DESCRIPTION
TRANSCRIPT
Introdução ao desenvolvimento em
Androidby Tiago Brito
Sunday, February 5, 12
Me
Tiago Brito
• Software developer @ be.ubi
• PHP | Symfony | Doctrine | mySQL | jQuery | git
• Android programmer since 2009
Sunday, February 5, 12
Apps
VATChecker
Sunday, February 5, 12
Apps
Dicionário
VATChecker
Sunday, February 5, 12
Apps
Dicionário
Jogos de Apostas
VATChecker
Sunday, February 5, 12
Apps
Movies
Dicionário
Jogos de Apostas
VATChecker
Sunday, February 5, 12
Apps
Movies Trânsito
Dicionário
Jogos de Apostas
VATChecker
Sunday, February 5, 12
Apps
Cultura
Movies Trânsito
Dicionário
Jogos de Apostas
VATChecker
Sunday, February 5, 12
Apps
Cultura
Movies Trânsito
Dicionário
CCilhavoJogos de Apostas
VATChecker
Sunday, February 5, 12
Apps
Cultura
Movies
Horóscopo
Trânsito
Dicionário
CCilhavoJogos de Apostas
VATChecker
Sunday, February 5, 12
Apps
Cultura
Movies
Horóscopo
Trânsito
Dicionário
CCilhavoJogos de Apostas
SinónimosVATChecker
Sunday, February 5, 12
Apps
Portagens
Cultura
Movies
Horóscopo
Trânsito
Dicionário
CCilhavoJogos de Apostas
SinónimosVATChecker
Sunday, February 5, 12
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 xxxx@priberam.ptCC: DirecçãoJurídica <DireccaoJuridica@priberam.pt>
Sunday, February 5, 12
Petiscos
Sunday, February 5, 12
Trânsito
Sunday, February 5, 12
Smart-lampgit rep: https://github.com/casainho/smart-lamp
Sunday, February 5, 12
Smart-lampgit rep: https://github.com/casainho/smart-lamp
Sunday, February 5, 12
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
Target Your AppSerious
Entertainment
Fun
Tool
content
usageSunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usageSunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usage
Sunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usageSerious Tool
•Productivity Type•Minimal UI•Create, modify, archieve
Sunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usageSunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usage
Sunday, February 5, 12
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
Target Your AppSerious
Entertainment
Fun
Tool
content
usageSunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usage
Sunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usage
Serious Entertainment• No Productivity• Educacional entertainment• Data driven• Potentially hierarchical
Sunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usageSunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usage
Sunday, February 5, 12
Target Your AppSerious
Entertainment
Fun
Tool
content
usageUtilities
• Rich Graphics• Single Screen• Ag in app 30 to 60s
Sunday, February 5, 12
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
Dalvik.equals(Java) == false
Sunday, February 5, 12
Anatomy of an Android Application
• Activity
• Intent Receiver
• Service
• Content Provider
Sunday, February 5, 12
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
Activity Lifecycle
Sunday, February 5, 12
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
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
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
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
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
MVC
Model View
Controler
Sunday, February 5, 12
Development Tools
• Eclipse plugin
• Android SDK
Sunday, February 5, 12
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
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
Common Problems
Sunday, February 5, 12
Common Problems
• ANR (App Not Responding)block main thread for more than 5 seconds
• Manifest missing configurations
Sunday, February 5, 12
Common ProblemsDon’t block the main thread
Sunday, February 5, 12
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
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
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
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
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
Performance
RecyclerSunday, February 5, 12
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
Demo
This slide has been deliberately left blank
Sunday, February 5, 12
Android Market• 25$ registation fee for developers
• 30 / 70
Sunday, February 5, 12
Android Market
Sunday, February 5, 12
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
Market
Sunday, February 5, 12
Market
• Right now, Portuguese market is too small for mobile ads revenue.
• Take advantage of Portuguese language
• Think Global.
Sunday, February 5, 12
Market
• Right now, Portuguese market is too small for mobile ads revenue.
• Take advantage of Portuguese language
• Think Global.
Sunday, February 5, 12
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
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
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.html
Sunday, February 5, 12
The end
Tiago Brito
tlfbrito@gmail.com@tlfbrito
Sunday, February 5, 12
top related