Upload
leandro-rezende
View
1.363
Download
5
Embed Size (px)
DESCRIPTION
Citation preview
Desenvolvimento de Aplicações para
Dispositivos MóveisIntrodução
Prof. Leandro Rezende C. de Mendonça, MSc.
terça-feira, 20 de setembro de 11
Open Handset Alliance
• http://www.openhandsetalliance.com
terça-feira, 20 de setembro de 11
Plataformas
• Symbian (Nokia)
• iPhone - iOS 4.2 (Apple)
• Windows Mobile (Microsoft)
• Blackberry (RIM)
• Java Mobile Edition (Sun)
• Linux Mobile (LiMo)
• Android - (Google)
terça-feira, 20 de setembro de 11
Android
• Open Source, without royalty;
• Based on Linux;
• Not locked into one vendor;
• Component-based architecture;
• Optimized for low-power, low-memory devices;
• Support 2D, 3D OpenGL, Flash, H.264(AVC), MP3 e AAC;
terça-feira, 20 de setembro de 11
Android Virtual Machine
• Android Dalvik Virtual Machine (Developer by Dan Bornstein at Google);
• Java Language;
• Java Libraries are different from both JavaSE and JavaME;
• Code portable across ARM, x86 and other architectures;
terça-feira, 20 de setembro de 11
Versões do Android
• 1.5 (Cupcake) - 1.000 changes to 1.1
• 1.6 (Donut) - High and Low displays
• 2.0 (Eclair) - Multi-touch, docking, virtual keys, HTML5, synchronization APIs etc.
• 2.1 (Eclair Maintenance) - Live wall-papers, more HTML5 and Widgets
• 2.2 (FroYo) - Application installation on external SD, faster virtual machine, OpenGL ES 2.0 APIs etc.
terça-feira, 20 de setembro de 11
Ambiente de Desenvolvimento
• Java 5.0 +
• Eclipse 3.3.1 + ADT(Android Development Tool)
• http://developer.android.com/sdk/eclipse-adt.html
• Netbeans 6.9.1+ plugin nbandroid (http://kenai.com/downloads/nbandroid)
• Android SDK (http://d.android.com/sdk/)
terça-feira, 20 de setembro de 11
Android Architecture
terça-feira, 20 de setembro de 11
Android ArchitectureTHE BIG PICTURE 31
Figure 2.1: Android system architecture
make Linux calls directly. As a developer, though, you’ll need to be
aware it’s there.
Some utilities you need during development interact with Linux. For
example, the adb shell command1 will open a Linux shell in which you
can enter other commands to run on the device. From there you can
examine the Linux file system, view active processes, and so forth, sub-
ject to security restrictions.
Native Libraries
The next layer above the kernel contains the Android native libraries.
These shared libraries are all written in C or C++, compiled for the
particular hardware architecture used by the phone, and preinstalled
by the phone vendor.
Some of the most important native libraries include the following:
• Surface Manager: Android uses a compositing window manager
similar to Vista or Compiz, but it’s much simpler. Instead of draw-
1. http://d.android.com/guide/developing/tools/adb.html
Report erratum
this copy is (P1.0 printing, July 2010)From Library of Wow! eBook
C/C++
JAVA
terça-feira, 20 de setembro de 11
Android Application
terça-feira, 20 de setembro de 11
Android ApplicationIT’S ALIVE! 36
Figure 2.2: The Home application
In Android, an application can be “alive” even if its process has been
killed. Put another way, the activity life cycle is not tied to the process
life cycle. Processes are just disposable containers for activities. This is
probably different from every other system you’re familiar with, so let’s
take a closer look before moving on.
Life Cycles of the Rich and Famous
During its lifetime, each activity of an Android program can be in one
of several states, as shown in Figure 2.3, on the next page. You, the
developer, do not have control over what state your program is in. That’s
all managed by the system. However, you do get notified when the state
is about to change through the onXX () method calls.
You override these methods in your Activity class, and Android will call
them at the appropriate time:
• onCreate(Bundle): This is called when the activity first starts up.
You can use it to perform one-time initialization such as creatingReport erratum
this copy is (P1.0 printing, July 2010)From Library of Wow! eBook
Process != Application
terça-feira, 20 de setembro de 11
Android Emulator
terça-feira, 20 de setembro de 11
Android Emulator
terça-feira, 20 de setembro de 11
Android Emulator
terça-feira, 20 de setembro de 11
Android Emulator
Ctrl + F11 Flip Screen
terça-feira, 20 de setembro de 11
Activity
• É toda Classe que herda da classe android.app.Activity;
• Controla os eventos da tela e apresenta a View desejada;
• Cada aplicação no Android é definida como uma Activity;
terça-feira, 20 de setembro de 11
Android Life Cicle
terça-feira, 20 de setembro de 11
Android Life CicleIT’S ALIVE! 37
Figure 2.3: Life cycle of an Android activity
the user interface. onCreate( ) takes one parameter that is either
null or some state information previously saved by the onSaveIn-
stanceState( ) method.
• onStart( ): This indicates the activity is about to be displayed to the
user.
• onResume( ): This is called when your activity can start interacting
with the user. This is a good place to start animations and music.
• onPause( ): This runs when the activity is about to go into the back-
ground, usually because another activity has been launched in
front of it. This is where you should save your program’s persis-
tent state, such as a database record being edited.
• onStop( ): This is called when your activity is no longer visible to
the user and it won’t be needed for a while. If memory is tight,
onStop( ) may never be called (the system may simply terminate
your process).
Report erratum
this copy is (P1.0 printing, July 2010)From Library of Wow! eBook
terça-feira, 20 de setembro de 11
Ciclo de Vida• Criar o projeto Lab01
• Abra o LogCat para visualizar as transições de estados
• Window > Show View > Other > Android > LogCat
terça-feira, 20 de setembro de 11
Testes de Transições de Estados
• 1 - Execute a aplicação e observe os log’s;
• 2 - Clique no botão voltar do emulador ou aperte a tecla ESC e observe os log’s;
• 3 - Na tela inicial do emulador abra novamente a aplicação e observe os log’s;
• 4 - Após abrir novemente a aplicação clique no botão HOME do emulador e observe os log’s.
terça-feira, 20 de setembro de 11
Testes de Transições de Estados
• 5 - Execute novamente a aplicação e observe os log’s;
• 6 - Vamos simular uma ligação e observar os log’s;
• Conecte via telnet no emulador execute os comandos e observe os log’s:
• $ telnet localhost 5554
• gsm call 32223333
• sms send 32223333 testeterça-feira, 20 de setembro de 11
Activity• Aplicações mais complexas possuem várias
telas (Activity’s)
• Métodos para iniciar outra Activity(Tela):
• startActivity(intent): Inicia a próxima tela sem qualquer vínculo entre telas.
• startActivityForResult(codigo, resultado, intent): Usado retornar resultados para a tela principal, ou seja manter vínculo entre telas.
terça-feira, 20 de setembro de 11
Activity
• Exemplo para abrir outra tela utilizando o método startActivity:
• Criar o projeto Lab02
terça-feira, 20 de setembro de 11
Activity• OBS: Informe no arquivo AndroidManifest.xml
do projeto a criação de uma nova Activity, adicionando a seguinte linha no arquivo.
terça-feira, 20 de setembro de 11
Ciclo de Vida - Activity• Abra o LogCat para visualizar as transições
de estados quando as telas são alternadas.
• Window > Show View > Other > Android > LogCat
terça-feira, 20 de setembro de 11
Ciclo de Vida - Activity
• Com o LOGCAT ainda aberto simule uma ligação através do terminal e observe as transições das telas.
• $ telnet localhost 5554
• gsm call 32223333
terça-feira, 20 de setembro de 11
Activity - Passagem de parâmetro
• Faça uma cópia do projeto Lab02 para Lab03.
• Iremos adicionar código para a passagem de parâmetro da uma tela para a outra:
• Primeiro no método onClick da classe main, depois no método onCreate da classe Tela2.
terça-feira, 20 de setembro de 11
Activity - Passagem de parâmetro
• Abra o LogCat para visualizar o parâmetro enviado para a Tela 2.
• Window > Show View > Other > Android > LogCat
terça-feira, 20 de setembro de 11
Fim
• Dúvidas ?
• Perguntas ?
terça-feira, 20 de setembro de 11