• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android Development Course in HSE lecture #3
 

Android Development Course in HSE lecture #3

on

  • 719 views

Activity Lifecycle, Views, Layouts

Activity Lifecycle, Views, Layouts

Statistics

Views

Total Views
719
Views on SlideShare
719
Embed Views
0

Actions

Likes
0
Downloads
13
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Android Development Course in HSE lecture #3 Android Development Course in HSE lecture #3 Presentation Transcript

    • Lecture #3
    • 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)
    • DDMS
    • Log.i("my_log_tag", "gotcha!");
    • Activity
    • public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_layout); }}
    • 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>
    • Declaring new Activities<activity android:name=".AnotherActivity"></activity> НЕ ЗАБЫВАЙТЕ!
    • Starting new ActivityIntent i = new Intent(context, NextActivity.class);startActivity(intent);context:● this● MyActivity.this● getApplicationContext()
    • 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);● подготовка пользовательского интерфейса● инициализация переменных класса (если нужно)● вызывается единожды за жизненный цикл Activity● не выполняйте "тяжелых" задач в onCreate()
    • Pausing and Resuming an Activity● Остановить анимации, звук, видео и т.д.● Сохранить состояние экрана (light auto- save only)● Очистить системные ресурсы (broadcast receivers, handlers to sensors (like GPS), camera, ...)● не выполняйте "тяжелых" задач в onPause()● В onResume(), наоборот, все восстанавливается (не забывайте, что вызывается каждый раз)
    • Stopping and Restarting an Activity● Максимально очистить все ресурсы● Сохранить состояние экрана (heavy operations)● В onStart(), наоборот, все восстанавливается (не забывайте, что вызывается каждый раз)
    • Recreating an Activity● onSaveInstanceState(Bundle savedInstanceState)● onRestoreInstanceState(Bundle savedInstanceState)● onCreate(Bundle savedInstanceState)
    • ● onDestroy()● onRestart()
    • github repo@Overrideprotected void onPause() { super.onPause(); Log.i("fsq", "onPause 1st");} НЕ ЗАБЫВАЙТЕ ВЫЗЫВАТЬ SUPER!
    • Android UI
    • LayoutParams android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_width="100dip" android: layout_height="100dip"
    • К каждому View применимыследующие listenerы● OnClickListener● OnLongClickListener● OnTouchListener● OnDragListener● OnTouchListener● OnKeyListener
    • padding and layout_margin● android:padding="5dip"● android:paddingRight="5dip"● android:layout_margin="5dip"● android:layout_marginRight="5dip" dp or dip
    • TextView● android:text="@string/text"● android:textColor="@android:color/black"● android:textStyle="italic|bold"● android:textSize="14sp" sp
    • Buttons● Button● ImageButton● android:text="@string/button_text"● android:src="@drawable/button_icon"● android:background="@android:color/transparent" (for ImageButton)● selector (for ImageButton)
    • 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 }});
    • ● 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:layout_centerVertical="true" ● android:layout_toRightOf="@+id/id" ● android:layout_below="@+id/id"
    • 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