Android Development Course in HSE lecture #3
Upcoming SlideShare
Loading in...5

Android Development Course in HSE lecture #3



Activity Lifecycle, Views, Layouts

Activity Lifecycle, Views, Layouts



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



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.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
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(;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 // break; case // 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