2 Activity & Layout Anuchit Chalothorn anoochit@gmail.comLicensed under a Creative Commons Attribution-NonCommercial-Share...
Quote การทําอะไรให ้ถึงขันเทพนัน ไม่เคยง่าย มีแต่ความมุงมัน อดทน                                                     ่    ...
ActivityAn activity represents the visual representationof an Android application. activities use views, i.e. user interfa...
Activity Life Cycle
Created
Paused and Resumed
Stopped
Save and Restore State
Workshop: Trace Activity Life CycleYou can use Log or Toast to check life cycle ofactivity on each methods;   ● onCreate  ...
Activity LayoutThe user interface for Activities is typicallydefined via XML files (layout files).
Trick: Single TaskPrevent create instance of Activity, you canidentify launchMode in AndroidManifest.xml● force for single...
Trick: Screen OrientationYou can identify the screen orientation byconfig in AndroidManifest.xml● Portrait   ○ android:scr...
Multiple ActivitiesSingle App has at least 1 Activity, complex apphas multiple activity. You can call to anotheractivity u...
Workshop: Two ActivitiesCreate App with 2 Activities each activity has abutton for navigate to other activity. UsingIntent...
Workshop: Sent data between activityCreate App with 2 Activities, first activity hastext field and button, after push butt...
Sent a valueUsing putExtra method to create a variable andidentify value;Intent i = new Intent(getApplicationContext(),New...
Receive a valueUsing getExtras methods to receive value fromvariable;Bundle extras = getIntent().getExtras();if (extras !=...
Workshop: Temperature ConverterCreate multiple Activity App, temperatureconverter between Celsius and Fahrenheitusing the ...
LayoutsAndroid has different layouts for place anwidgets● Linear Layout● Relative Layout● Frame Layout
Workshop: App with Relative LayoutCreate single Activity App with Label andButton using Relative Layout and see howrelativ...
Workshop: App with Linear LayoutCreate single Activity App with Label andButton using Linear Layout and see how thelinear ...
Workshop: App with Frame LayoutCreate single Activity App with Label andButton using Frame Layout and see how theframe lay...
Trick: Dump LayoutYou can use DDMS tool to dump screen to seethe layout design and properties
End
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Android App Development 02 : Activity & Layout
Upcoming SlideShare
Loading in...5
×

Android App Development 02 : Activity & Layout

370

Published on

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
370
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Android App Development 02 : Activity & Layout

  1. 1. 2 Activity & Layout Anuchit Chalothorn anoochit@gmail.comLicensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  2. 2. Quote การทําอะไรให ้ถึงขันเทพนัน ไม่เคยง่าย มีแต่ความมุงมัน อดทน ่ อย่างยาวนานเท่านัน ทีจะทําให ้บรรลุได ้ วิถแห่งเทพนันย่อมเต็มไปด ้วยความยากลําบากเสมอ ี อันเทพแห่งศาสตร์ใด เริมต ้นต ้องมีความรักอย่างงมงายในศาสตร์นัน มีความพากเพียรในการศึกษาจนแตกฉาน ฝึ กหัดอย่างอดทน หมันพิจารณาแก ้ไขให ้ศาสตร์แห่งตนย่างเข ้าสูความสมบูรณ์ ่ อัจฉริยภาพแค่ชวยลดเวลาแห่งความยากลําบากให ้สันลงเท่านัน ่แต่หากปราศจากความมุงมันแล ้ว ต่อให ้มีอจฉริยภาพสักเพียงไหน ่ ั ย่อมไม่สามารถถึงซึงความเป็ นเลิศนันได ้เลย -- ภุชงค์ อุทโยภาศ
  3. 3. ActivityAn activity represents the visual representationof an Android application. activities use views, i.e. user interface widgets as for examplebuttons to create the user interface and tointeract with the user. An Android applicationcan have several activities.
  4. 4. Activity Life Cycle
  5. 5. Created
  6. 6. Paused and Resumed
  7. 7. Stopped
  8. 8. Save and Restore State
  9. 9. Workshop: Trace Activity Life CycleYou can use Log or Toast to check life cycle ofactivity on each methods; ● onCreate ● onStart ● onResume ● onPause ● onStop ● onDestroy
  10. 10. Activity LayoutThe user interface for Activities is typicallydefined via XML files (layout files).
  11. 11. Trick: Single TaskPrevent create instance of Activity, you canidentify 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"
  12. 12. Trick: Screen OrientationYou can identify the screen orientation byconfig in AndroidManifest.xml● Portrait ○ android:screenOrientation="portrait"● Landscape ○ android:screenOrientation="landscape"● Landscape with No Keyboard ○ android:configChange="orientation|kyboardHidden"
  13. 13. Multiple ActivitiesSingle App has at least 1 Activity, complex apphas multiple activity. You can call to anotheractivity using Intent.
  14. 14. Workshop: Two ActivitiesCreate App with 2 Activities each activity has abutton for navigate to other activity. UsingIntent to call another activity.Intent i = new Intent(MainActivity.this,SecondActivity);startactivity(i);
  15. 15. Workshop: Sent data between activityCreate App with 2 Activities, first activity hastext field and button, after push button itll sentdata in text field to the second activity. UsingputExtra method to create a variable andidentify value;Intent i = new Intent(getApplicationContext(),NewActivity.class);i.putExtra("new_variable_name","value");startActivity(i);
  16. 16. Sent a valueUsing putExtra method to create a variable andidentify value;Intent i = new Intent(getApplicationContext(),NewActivity.class);i.putExtra("new_variable_name","value");startActivity(i);
  17. 17. Receive a valueUsing getExtras methods to receive value fromvariable;Bundle extras = getIntent().getExtras();if (extras != null) { String value = extras.getString("new_variable_name");}
  18. 18. Workshop: Temperature ConverterCreate multiple Activity App, temperatureconverter between Celsius and Fahrenheitusing the following formula °C x 9/5 + 32 = °F (°F - 32) x 5/9 = °C
  19. 19. LayoutsAndroid has different layouts for place anwidgets● Linear Layout● Relative Layout● Frame Layout
  20. 20. Workshop: App with Relative LayoutCreate single Activity App with Label andButton using Relative Layout and see howrelative layout work.
  21. 21. Workshop: App with Linear LayoutCreate single Activity App with Label andButton using Linear Layout and see how thelinear layout work.
  22. 22. Workshop: App with Frame LayoutCreate single Activity App with Label andButton using Frame Layout and see how theframe layout work.
  23. 23. Trick: Dump LayoutYou can use DDMS tool to dump screen to seethe layout design and properties
  24. 24. End
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×