Android App Development 02 : Activity & Layout
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Android App Development 02 : Activity & Layout

  • 578 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • หน้าแรกก็เทพแล้วอ่ะ
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
578
On Slideshare
561
From Embeds
17
Number of Embeds
1

Actions

Shares
Downloads
12
Comments
1
Likes
0

Embeds 17

http://www.classstart.org 17

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 2 Activity & Layout Anuchit Chalothorn anoochit@gmail.comLicensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. Quote การทําอะไรให ้ถึงขันเทพนัน ไม่เคยง่าย มีแต่ความมุงมัน อดทน ่ อย่างยาวนานเท่านัน ทีจะทําให ้บรรลุได ้ วิถแห่งเทพนันย่อมเต็มไปด ้วยความยากลําบากเสมอ ี อันเทพแห่งศาสตร์ใด เริมต ้นต ้องมีความรักอย่างงมงายในศาสตร์นัน มีความพากเพียรในการศึกษาจนแตกฉาน ฝึ กหัดอย่างอดทน หมันพิจารณาแก ้ไขให ้ศาสตร์แห่งตนย่างเข ้าสูความสมบูรณ์ ่ อัจฉริยภาพแค่ชวยลดเวลาแห่งความยากลําบากให ้สันลงเท่านัน ่แต่หากปราศจากความมุงมันแล ้ว ต่อให ้มีอจฉริยภาพสักเพียงไหน ่ ั ย่อมไม่สามารถถึงซึงความเป็ นเลิศนันได ้เลย -- ภุชงค์ อุทโยภาศ
  • 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. Activity Life Cycle
  • 5. Created
  • 6. Paused and Resumed
  • 7. Stopped
  • 8. Save and Restore State
  • 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. Activity LayoutThe user interface for Activities is typicallydefined via XML files (layout files).
  • 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. 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. Multiple ActivitiesSingle App has at least 1 Activity, complex apphas multiple activity. You can call to anotheractivity using Intent.
  • 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. 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. 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. Receive a valueUsing getExtras methods to receive value fromvariable;Bundle extras = getIntent().getExtras();if (extras != null) { String value = extras.getString("new_variable_name");}
  • 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. LayoutsAndroid has different layouts for place anwidgets● Linear Layout● Relative Layout● Frame Layout
  • 20. Workshop: App with Relative LayoutCreate single Activity App with Label andButton using Relative Layout and see howrelative layout work.
  • 21. Workshop: App with Linear LayoutCreate single Activity App with Label andButton using Linear Layout and see how thelinear layout work.
  • 22. Workshop: App with Frame LayoutCreate single Activity App with Label andButton using Frame Layout and see how theframe layout work.
  • 23. Trick: Dump LayoutYou can use DDMS tool to dump screen to seethe layout design and properties
  • 24. End