Lecture #3
Logs●   Log.i(tag, msg); (information)●   Log.v(tag, msg); (verbose)●   Log.d(tag, msg); (debug)●   Log.w(tag, msg); (warn...
DDMS
Log.i("my_log_tag", "gotcha!");
Activity
public class MyActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {    super.onCr...
Declaring "launcher" Activity<activity     android:name=".MyActivity" >     <intent-filter>          <action android:name=...
Declaring new Activities<activity   android:name=".AnotherActivity"></activity>      НЕ ЗАБЫВАЙТЕ!
Starting new ActivityIntent i = new Intent(context, NextActivity.class);startActivity(intent);context:●   this●   MyActivi...
Activity Lifecycle
Activity states● Resumed ("running")● Paused● Stopped
Lifecycle methods●   onCreate()●   onRestart()●   onStart()●   onResume()●   onPause()●   onStop()●   onDestroy()
Starting an Activity● setContentView(R.layout.my_layout);● подготовка пользовательского  интерфейса● инициализация перемен...
Pausing and Resuming an Activity● Остановить анимации, звук, видео и т.д.● Сохранить состояние экрана (light auto-  save o...
Stopping and Restarting an Activity● Максимально очистить все ресурсы● Сохранить состояние экрана (heavy  operations)● В o...
Recreating an Activity● onSaveInstanceState(Bundle savedInstanceState)● onRestoreInstanceState(Bundle savedInstanceState)●...
● onDestroy()● onRestart()
github repo@Overrideprotected void onPause() {  super.onPause();  Log.i("fsq", "onPause 1st");}   НЕ ЗАБЫВАЙТЕ  ВЫЗЫВАТЬ S...
Android UI
LayoutParams               android:layout_width="fill_parent"               android:layout_height="wrap_content"          ...
К каждому View применимыследующие listenerы●   OnClickListener●   OnLongClickListener●   OnTouchListener●   OnDragListener...
padding and layout_margin●   android:padding="5dip"●   android:paddingRight="5dip"●   android:layout_margin="5dip"●   andr...
TextView●   android:text="@string/text"●   android:textColor="@android:color/black"●   android:textStyle="italic|bold"●   ...
Buttons● Button● ImageButton● android:text="@string/button_text"● android:src="@drawable/button_icon"● android:background=...
Button button = (Button) findViewById(R.id.button_send);button.setOnClickListener(new View.OnClickListener() {     public ...
● button.setOnClickListener(this)● button.setOnClickListener(myClickListener)● android:onClick="clickMethod"
switch (v.getId()) {  case R.id.button1:     //     break;  case R.id.button2:     //     break;}
EditText●   editText.getText();●   android:inputType="textEmailAddress"●   OnEditorActionListener●   OnTextChangedListener
ImageView            android:src="@drawable/icon"            android:scaleType="fitXY"
● CheckBox● RadioButton● ToggleButton
Pickers
ListView and GridView
LinearLayout
RelativeLayout                 ●   android:layout_alignParentLeft="                     true"                 ●   android:...
FrameLayout
ScrollView
gravity● android:gravity="center"● android:layout_gravity="center_horizontal|right"
weight   ● android:weight="1"   ● android:layout_width="0dip"
ToastToast.makeText(context, text, duration).show();
Resources for multiple screens●   drawable●   drawable-xhdpi●   drawable-hdpi●   drawable-mdpi●   layout●   layout-land
Other Resources●   anim●   assets●   libs●   values
External jars   Хранить в папке libs!
Android Library Project
MenuNo Context menu is a good Context menu (c)
Homework● Activity Lifecycle● Views and Layouts
Android Development Course in HSE lecture #3
Upcoming SlideShare
Loading in …5
×

Android Development Course in HSE lecture #3

499
-1

Published on

Activity Lifecycle, Views, Layouts

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
499
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android Development Course in HSE lecture #3

  1. 1. Lecture #3
  2. 2. Logs● Log.i(tag, msg); (information)● Log.v(tag, msg); (verbose)● Log.d(tag, msg); (debug)● Log.w(tag, msg); (warning)● Log.e(tag, msg); (error)
  3. 3. DDMS
  4. 4. Log.i("my_log_tag", "gotcha!");
  5. 5. Activity
  6. 6. public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_layout); }}
  7. 7. Declaring "launcher" Activity<activity android:name=".MyActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter></activity>
  8. 8. Declaring new Activities<activity android:name=".AnotherActivity"></activity> НЕ ЗАБЫВАЙТЕ!
  9. 9. Starting new ActivityIntent i = new Intent(context, NextActivity.class);startActivity(intent);context:● this● MyActivity.this● getApplicationContext()
  10. 10. Activity Lifecycle
  11. 11. Activity states● Resumed ("running")● Paused● Stopped
  12. 12. Lifecycle methods● onCreate()● onRestart()● onStart()● onResume()● onPause()● onStop()● onDestroy()
  13. 13. Starting an Activity● setContentView(R.layout.my_layout);● подготовка пользовательского интерфейса● инициализация переменных класса (если нужно)● вызывается единожды за жизненный цикл Activity● не выполняйте "тяжелых" задач в onCreate()
  14. 14. Pausing and Resuming an Activity● Остановить анимации, звук, видео и т.д.● Сохранить состояние экрана (light auto- save only)● Очистить системные ресурсы (broadcast receivers, handlers to sensors (like GPS), camera, ...)● не выполняйте "тяжелых" задач в onPause()● В onResume(), наоборот, все восстанавливается (не забывайте, что вызывается каждый раз)
  15. 15. Stopping and Restarting an Activity● Максимально очистить все ресурсы● Сохранить состояние экрана (heavy operations)● В onStart(), наоборот, все восстанавливается (не забывайте, что вызывается каждый раз)
  16. 16. Recreating an Activity● onSaveInstanceState(Bundle savedInstanceState)● onRestoreInstanceState(Bundle savedInstanceState)● onCreate(Bundle savedInstanceState)
  17. 17. ● onDestroy()● onRestart()
  18. 18. github repo@Overrideprotected void onPause() { super.onPause(); Log.i("fsq", "onPause 1st");} НЕ ЗАБЫВАЙТЕ ВЫЗЫВАТЬ SUPER!
  19. 19. Android UI
  20. 20. LayoutParams android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_width="100dip" android: layout_height="100dip"
  21. 21. К каждому View применимыследующие listenerы● OnClickListener● OnLongClickListener● OnTouchListener● OnDragListener● OnTouchListener● OnKeyListener
  22. 22. padding and layout_margin● android:padding="5dip"● android:paddingRight="5dip"● android:layout_margin="5dip"● android:layout_marginRight="5dip" dp or dip
  23. 23. TextView● android:text="@string/text"● android:textColor="@android:color/black"● android:textStyle="italic|bold"● android:textSize="14sp" sp
  24. 24. Buttons● Button● ImageButton● android:text="@string/button_text"● android:src="@drawable/button_icon"● android:background="@android:color/transparent" (for ImageButton)● selector (for ImageButton)
  25. 25. Button button = (Button) findViewById(R.id.button_send);button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Do something in response to button click }});
  26. 26. ● button.setOnClickListener(this)● button.setOnClickListener(myClickListener)● android:onClick="clickMethod"
  27. 27. switch (v.getId()) { case R.id.button1: // break; case R.id.button2: // break;}
  28. 28. EditText● editText.getText();● android:inputType="textEmailAddress"● OnEditorActionListener● OnTextChangedListener
  29. 29. ImageView android:src="@drawable/icon" android:scaleType="fitXY"
  30. 30. ● CheckBox● RadioButton● ToggleButton
  31. 31. Pickers
  32. 32. ListView and GridView
  33. 33. LinearLayout
  34. 34. RelativeLayout ● android:layout_alignParentLeft=" true" ● android:layout_centerVertical="true" ● android:layout_toRightOf="@+id/id" ● android:layout_below="@+id/id"
  35. 35. FrameLayout
  36. 36. ScrollView
  37. 37. gravity● android:gravity="center"● android:layout_gravity="center_horizontal|right"
  38. 38. weight ● android:weight="1" ● android:layout_width="0dip"
  39. 39. ToastToast.makeText(context, text, duration).show();
  40. 40. Resources for multiple screens● drawable● drawable-xhdpi● drawable-hdpi● drawable-mdpi● layout● layout-land
  41. 41. Other Resources● anim● assets● libs● values
  42. 42. External jars Хранить в папке libs!
  43. 43. Android Library Project
  44. 44. MenuNo Context menu is a good Context menu (c)
  45. 45. Homework● Activity Lifecycle● Views and Layouts
  1. A particular slide catching your eye?

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

×