SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
2
 Activity & Layout
 Anuchit Chalothorn
 anoochit@gmail.com

Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Quote
 การทําอะไรให ้ถึงขันเทพนัน ไม่เคยง่าย มีแต่ความมุงมัน อดทน
                                                     ่
               อย่างยาวนานเท่านัน ทีจะทําให ้บรรลุได ้
       วิถแห่งเทพนันย่อมเต็มไปด ้วยความยากลําบากเสมอ
          ี
             อันเทพแห่งศาสตร์ใด เริมต ้นต ้องมีความรัก
อย่างงมงายในศาสตร์นัน มีความพากเพียรในการศึกษาจนแตกฉาน
                        ฝึ กหัดอย่างอดทน
    หมันพิจารณาแก ้ไขให ้ศาสตร์แห่งตนย่างเข ้าสูความสมบูรณ์
                                                 ่
 อัจฉริยภาพแค่ชวยลดเวลาแห่งความยากลําบากให ้สันลงเท่านัน
                   ่
แต่หากปราศจากความมุงมันแล ้ว ต่อให ้มีอจฉริยภาพสักเพียงไหน
                        ่                  ั
            ย่อมไม่สามารถถึงซึงความเป็ นเลิศนันได ้เลย

                                  -- ภุชงค์ อุทโยภาศ
Activity
An activity represents the visual representation
of an Android application. activities use views, i.
e. user interface widgets as for example
buttons to create the user interface and to
interact with the user. An Android application
can have several activities.
Activity Life Cycle
Created
Paused and Resumed
Stopped
Save and Restore State
Workshop: Trace Activity Life Cycle
You can use Log or Toast to check life cycle of
activity on each methods;
   ● onCreate
   ● onStart
   ● onResume
   ● onPause
   ● onStop
   ● onDestroy
Activity Layout
The user interface for Activities is typically
defined via XML files (layout files).
Trick: Single Task
Prevent create instance of Activity, you can
identify launchMode in AndroidManifest.xml
● force for single instance
   ○ android:launchMode="singleInstance"
● force for single task
   ○ android:launchMode="singleTask"
● force app to recognize latest state
   ○ android:alwaysRetainTaskState="true"
Trick: Screen Orientation
You can identify the screen orientation by
config in AndroidManifest.xml
● Portrait
   ○ android:screenOrientation="portrait"
● Landscape
   ○ android:screenOrientation="landscape"
● Landscape with No Keyboard
   ○ android:configChange="orientation|kyboardHidden"
Multiple Activities
Single App has at least 1 Activity, complex app
has multiple activity. You can call to another
activity using Intent.
Workshop: Two Activities
Create App with 2 Activities each activity has a
button for navigate to other activity. Using
Intent to call another activity.

Intent i = new Intent(MainActivity.this,SecondActivity);
startactivity(i);
Workshop: Sent data between activity
Create App with 2 Activities, first activity has
text field and button, after push button it'll sent
data in text field to the second activity. Using
putExtra method to create a variable and
identify value;

Intent i = new Intent(getApplicationContext(),
NewActivity.class);
i.putExtra("new_variable_name","value");
startActivity(i);
Sent a value
Using putExtra method to create a variable and
identify value;

Intent i = new Intent(getApplicationContext(),
NewActivity.class);
i.putExtra("new_variable_name","value");
startActivity(i);
Receive a value
Using getExtras methods to receive value from
variable;

Bundle extras = getIntent().getExtras();
if (extras != null) {
   String value = extras.getString("new_variable_name");
}
Workshop: Temperature Converter
Create multiple Activity App, temperature
converter between Celsius and Fahrenheit
using the following formula

             °C x 9/5 + 32 = °F
            (°F - 32) x 5/9 = °C
Layouts
Android has different layouts for place an
widgets
● Linear Layout
● Relative Layout
● Frame Layout
Workshop: App with Relative Layout
Create single Activity App with Label and
Button using Relative Layout and see how
relative layout work.
Workshop: App with Linear Layout
Create single Activity App with Label and
Button using Linear Layout and see how the
linear layout work.
Workshop: App with Frame Layout
Create single Activity App with Label and
Button using Frame Layout and see how the
frame layout work.
Trick: Dump Layout
You can use DDMS tool to dump screen to see
the layout design and properties
End

Más contenido relacionado

Destacado

Aula - 04 - Android - Interface grafica (layout, widgets)
Aula - 04 - Android - Interface grafica (layout, widgets)Aula - 04 - Android - Interface grafica (layout, widgets)
Aula - 04 - Android - Interface grafica (layout, widgets)Arthur Emanuel
 
Android Layout 3分クッキング
Android Layout 3分クッキングAndroid Layout 3分クッキング
Android Layout 3分クッキングYuki Anzai
 
Web Analytics and Usability Testing
Web Analytics and Usability TestingWeb Analytics and Usability Testing
Web Analytics and Usability TestingEva Kaniasty
 
Una - Testes de usabilidade - aula 01 e 02
Una - Testes de usabilidade - aula 01 e 02Una - Testes de usabilidade - aula 01 e 02
Una - Testes de usabilidade - aula 01 e 02Marcello Cardoso
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)Khaled Anaqwa
 
Android Layout Cookbook Seminor
Android Layout Cookbook SeminorAndroid Layout Cookbook Seminor
Android Layout Cookbook SeminorYuki Anzai
 
Una - Testes de usabilidade - aula 03
Una - Testes de usabilidade - aula 03Una - Testes de usabilidade - aula 03
Una - Testes de usabilidade - aula 03Marcello Cardoso
 
Usabilidade 5 - Análise Heurística
Usabilidade 5 - Análise HeurísticaUsabilidade 5 - Análise Heurística
Usabilidade 5 - Análise HeurísticaMarcello Cardoso
 
Usabilidade 7-8 - Teste de Usabilidade
Usabilidade 7-8 - Teste de UsabilidadeUsabilidade 7-8 - Teste de Usabilidade
Usabilidade 7-8 - Teste de UsabilidadeMarcello Cardoso
 
Una - Testes de usabilidade - aula 04
Una - Testes de usabilidade - aula 04Una - Testes de usabilidade - aula 04
Una - Testes de usabilidade - aula 04Marcello Cardoso
 
Usability Testing Bootcamp
Usability Testing BootcampUsability Testing Bootcamp
Usability Testing BootcampDavid Travis
 
Web Usability (Slideshare Version)
Web Usability (Slideshare Version)Web Usability (Slideshare Version)
Web Usability (Slideshare Version)Carles Farré
 
Usability Testing
Usability TestingUsability Testing
Usability TestingAndy Budd
 
Usability 2.0
Usability 2.0Usability 2.0
Usability 2.0Greg Bell
 
Introduction to Usability
Introduction to UsabilityIntroduction to Usability
Introduction to UsabilityGretchen Thomas
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Yuki Anzai
 
Prototyping and Usability Testing your designs
Prototyping and Usability Testing your designsPrototyping and Usability Testing your designs
Prototyping and Usability Testing your designsElizabeth Snowdon
 
Usability vs. User Experience: What's the difference?
Usability vs. User Experience: What's the difference?Usability vs. User Experience: What's the difference?
Usability vs. User Experience: What's the difference?Domain7
 

Destacado (19)

Aula - 04 - Android - Interface grafica (layout, widgets)
Aula - 04 - Android - Interface grafica (layout, widgets)Aula - 04 - Android - Interface grafica (layout, widgets)
Aula - 04 - Android - Interface grafica (layout, widgets)
 
Android Layout 3分クッキング
Android Layout 3分クッキングAndroid Layout 3分クッキング
Android Layout 3分クッキング
 
Web Analytics and Usability Testing
Web Analytics and Usability TestingWeb Analytics and Usability Testing
Web Analytics and Usability Testing
 
Una - Testes de usabilidade - aula 01 e 02
Una - Testes de usabilidade - aula 01 e 02Una - Testes de usabilidade - aula 01 e 02
Una - Testes de usabilidade - aula 01 e 02
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
 
Android Layout Cookbook Seminor
Android Layout Cookbook SeminorAndroid Layout Cookbook Seminor
Android Layout Cookbook Seminor
 
Una - Testes de usabilidade - aula 03
Una - Testes de usabilidade - aula 03Una - Testes de usabilidade - aula 03
Una - Testes de usabilidade - aula 03
 
Advance Android Layout Walkthrough
Advance Android Layout WalkthroughAdvance Android Layout Walkthrough
Advance Android Layout Walkthrough
 
Usabilidade 5 - Análise Heurística
Usabilidade 5 - Análise HeurísticaUsabilidade 5 - Análise Heurística
Usabilidade 5 - Análise Heurística
 
Usabilidade 7-8 - Teste de Usabilidade
Usabilidade 7-8 - Teste de UsabilidadeUsabilidade 7-8 - Teste de Usabilidade
Usabilidade 7-8 - Teste de Usabilidade
 
Una - Testes de usabilidade - aula 04
Una - Testes de usabilidade - aula 04Una - Testes de usabilidade - aula 04
Una - Testes de usabilidade - aula 04
 
Usability Testing Bootcamp
Usability Testing BootcampUsability Testing Bootcamp
Usability Testing Bootcamp
 
Web Usability (Slideshare Version)
Web Usability (Slideshare Version)Web Usability (Slideshare Version)
Web Usability (Slideshare Version)
 
Usability Testing
Usability TestingUsability Testing
Usability Testing
 
Usability 2.0
Usability 2.0Usability 2.0
Usability 2.0
 
Introduction to Usability
Introduction to UsabilityIntroduction to Usability
Introduction to Usability
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016
 
Prototyping and Usability Testing your designs
Prototyping and Usability Testing your designsPrototyping and Usability Testing your designs
Prototyping and Usability Testing your designs
 
Usability vs. User Experience: What's the difference?
Usability vs. User Experience: What's the difference?Usability vs. User Experience: What's the difference?
Usability vs. User Experience: What's the difference?
 

Más de Anuchit Chalothorn (20)

Flutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARUFlutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARU
 
Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020
 
13 web service integration
13 web service integration13 web service integration
13 web service integration
 
09 material design
09 material design09 material design
09 material design
 
07 intent
07 intent07 intent
07 intent
 
05 binding and action
05 binding and action05 binding and action
05 binding and action
 
04 layout design and basic widget
04 layout design and basic widget04 layout design and basic widget
04 layout design and basic widget
 
03 activity life cycle
03 activity life cycle03 activity life cycle
03 activity life cycle
 
02 create your first app
02 create your first app02 create your first app
02 create your first app
 
01 introduction
01 introduction 01 introduction
01 introduction
 
Material Theme
Material ThemeMaterial Theme
Material Theme
 
00 Android Wear Setup Emulator
00 Android Wear Setup Emulator00 Android Wear Setup Emulator
00 Android Wear Setup Emulator
 
MongoDB Replication Cluster
MongoDB Replication ClusterMongoDB Replication Cluster
MongoDB Replication Cluster
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
 
IT Automation with Puppet Enterprise
IT Automation with Puppet EnterpriseIT Automation with Puppet Enterprise
IT Automation with Puppet Enterprise
 
Using PhoneGap Command Line
Using PhoneGap Command LineUsing PhoneGap Command Line
Using PhoneGap Command Line
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 

Android App Development 02 : Activity & Layout

  • 1. 2 Activity & Layout Anuchit Chalothorn anoochit@gmail.com Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. Quote การทําอะไรให ้ถึงขันเทพนัน ไม่เคยง่าย มีแต่ความมุงมัน อดทน ่ อย่างยาวนานเท่านัน ทีจะทําให ้บรรลุได ้ วิถแห่งเทพนันย่อมเต็มไปด ้วยความยากลําบากเสมอ ี อันเทพแห่งศาสตร์ใด เริมต ้นต ้องมีความรัก อย่างงมงายในศาสตร์นัน มีความพากเพียรในการศึกษาจนแตกฉาน ฝึ กหัดอย่างอดทน หมันพิจารณาแก ้ไขให ้ศาสตร์แห่งตนย่างเข ้าสูความสมบูรณ์ ่ อัจฉริยภาพแค่ชวยลดเวลาแห่งความยากลําบากให ้สันลงเท่านัน ่ แต่หากปราศจากความมุงมันแล ้ว ต่อให ้มีอจฉริยภาพสักเพียงไหน ่ ั ย่อมไม่สามารถถึงซึงความเป็ นเลิศนันได ้เลย -- ภุชงค์ อุทโยภาศ
  • 3. Activity An activity represents the visual representation of an Android application. activities use views, i. e. user interface widgets as for example buttons to create the user interface and to interact with the user. An Android application can have several activities.
  • 9. Workshop: Trace Activity Life Cycle You can use Log or Toast to check life cycle of activity on each methods; ● onCreate ● onStart ● onResume ● onPause ● onStop ● onDestroy
  • 10.
  • 11. Activity Layout The user interface for Activities is typically defined via XML files (layout files).
  • 12.
  • 13.
  • 14. Trick: Single Task Prevent create instance of Activity, you can identify launchMode in AndroidManifest.xml ● force for single instance ○ android:launchMode="singleInstance" ● force for single task ○ android:launchMode="singleTask" ● force app to recognize latest state ○ android:alwaysRetainTaskState="true"
  • 15. Trick: Screen Orientation You can identify the screen orientation by config in AndroidManifest.xml ● Portrait ○ android:screenOrientation="portrait" ● Landscape ○ android:screenOrientation="landscape" ● Landscape with No Keyboard ○ android:configChange="orientation|kyboardHidden"
  • 16. Multiple Activities Single App has at least 1 Activity, complex app has multiple activity. You can call to another activity using Intent.
  • 17. Workshop: Two Activities Create App with 2 Activities each activity has a button for navigate to other activity. Using Intent to call another activity. Intent i = new Intent(MainActivity.this,SecondActivity); startactivity(i);
  • 18.
  • 19. Workshop: Sent data between activity Create App with 2 Activities, first activity has text field and button, after push button it'll sent data in text field to the second activity. Using putExtra method to create a variable and identify value; Intent i = new Intent(getApplicationContext(), NewActivity.class); i.putExtra("new_variable_name","value"); startActivity(i);
  • 20. Sent a value Using putExtra method to create a variable and identify value; Intent i = new Intent(getApplicationContext(), NewActivity.class); i.putExtra("new_variable_name","value"); startActivity(i);
  • 21. Receive a value Using getExtras methods to receive value from variable; Bundle extras = getIntent().getExtras(); if (extras != null) { String value = extras.getString("new_variable_name"); }
  • 22.
  • 23. Workshop: Temperature Converter Create multiple Activity App, temperature converter between Celsius and Fahrenheit using the following formula °C x 9/5 + 32 = °F (°F - 32) x 5/9 = °C
  • 24.
  • 25. Layouts Android has different layouts for place an widgets ● Linear Layout ● Relative Layout ● Frame Layout
  • 26. Workshop: App with Relative Layout Create single Activity App with Label and Button using Relative Layout and see how relative layout work.
  • 27.
  • 28. Workshop: App with Linear Layout Create single Activity App with Label and Button using Linear Layout and see how the linear layout work.
  • 29.
  • 30.
  • 31. Workshop: App with Frame Layout Create single Activity App with Label and Button using Frame Layout and see how the frame layout work.
  • 32.
  • 33. Trick: Dump Layout You can use DDMS tool to dump screen to see the layout design and properties
  • 34.
  • 35. End