+ All Categories
Home > Education > Android Development Course in HSE lecture #3

Android Development Course in HSE lecture #3

Date post: 13-May-2015
Category:
Upload: empatika
View: 446 times
Download: 0 times
Share this document with a friend
Description:
Activity Lifecycle, Views, Layouts
Popular Tags:
46
Lecture #3
Transcript
Page 1: Android Development Course in HSE lecture #3

Lecture #3

Page 2: Android Development Course in HSE 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)

Page 4: Android Development Course in HSE lecture #3

Log.i("my_log_tag", "gotcha!");

Page 6: Android Development Course in HSE lecture #3

public class MyActivity extends Activity {

@Overridepublic void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.my_layout);}

}

Page 7: Android Development Course in HSE lecture #3

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>

Page 8: Android Development Course in HSE lecture #3

Declaring new Activities

<activityandroid:name=".AnotherActivity">

</activity>

НЕ ЗАБЫВАЙТЕ!

Page 9: Android Development Course in HSE lecture #3

Starting new Activity

Intent i = new Intent(context, NextActivity.class);startActivity(intent);

context:

● this

● MyActivity.this

● getApplicationContext()

Page 10: Android Development Course in HSE lecture #3
Page 12: Android Development Course in HSE lecture #3

Activity states

● Resumed ("running")● Paused● Stopped

Page 13: Android Development Course in HSE lecture #3

Lifecycle methods

● onCreate()● onRestart()● onStart()● onResume()● onPause()● onStop()● onDestroy()

Page 14: Android Development Course in HSE lecture #3

Starting an Activity

● setContentView(R.layout.my_layout);● подготовка пользовательского

интерфейса● инициализация переменных класса (если

нужно)● вызывается единожды за жизненный

цикл Activity● не выполняйте "тяжелых" задач в

onCreate()

Page 15: Android Development Course in HSE lecture #3

Pausing and Resuming an Activity

● Остановить анимации, звук, видео и т.д.● Сохранить состояние экрана (light auto-

save only)● Очистить системные ресурсы (broadcast

receivers, handlers to sensors (like GPS), camera, ...)

● не выполняйте "тяжелых" задач в onPause()

● В onResume(), наоборот, все восстанавливается (не забывайте, что вызывается каждый раз)

Page 16: Android Development Course in HSE lecture #3

Stopping and Restarting an Activity

● Максимально очистить все ресурсы● Сохранить состояние экрана (heavy

operations)● В onStart(), наоборот, все

восстанавливается (не забывайте, что вызывается каждый раз)

Page 17: Android Development Course in HSE lecture #3

Recreating an Activity

● onSaveInstanceState(Bundle savedInstanceState)● onRestoreInstanceState(Bundle savedInstanceState)● onCreate(Bundle savedInstanceState)

Page 18: Android Development Course in HSE lecture #3

● onDestroy()● onRestart()

Page 19: Android Development Course in HSE lecture #3

github repo @Override protected void onPause() { super.onPause(); Log.i("fsq", "onPause 1st"); }

НЕ ЗАБЫВАЙТЕ ВЫЗЫВАТЬ SUPER!

Page 21: Android Development Course in HSE lecture #3

LayoutParams

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:layout_width="100dip" android:layout_height="100dip"

Page 23: Android Development Course in HSE lecture #3

padding and layout_margin

● android:padding="5dip"● android:paddingRight="5dip"● android:layout_margin="5dip"● android:layout_marginRight="5dip"

dp or dip

Page 24: Android Development Course in HSE lecture #3

TextView

● android:text="@string/text"● android:textColor="@android:color/black"● android:textStyle="italic|bold"● android:textSize="14sp"

sp

Page 26: Android Development Course in HSE lecture #3

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 }});

Page 27: Android Development Course in HSE lecture #3

● button.setOnClickListener(this)● button.setOnClickListener(myClickListener)● android:onClick="clickMethod"

Page 28: Android Development Course in HSE lecture #3

switch (v.getId()) {case R.id.button1:

//break;

case R.id.button2://break;

}

Page 29: Android Development Course in HSE lecture #3

EditText

● editText.getText();● android:inputType="textEmailAddress"● OnEditorActionListener ● OnTextChangedListener

Page 35: Android Development Course in HSE lecture #3

RelativeLayout

● android:layout_alignParentLeft="true"

● android:layout_centerVertical="true"● android:layout_toRightOf="@+id/id"● android:layout_below="@+id/id"

Page 38: Android Development Course in HSE lecture #3

gravity

● android:gravity="center"● android:layout_gravity="center_horizontal|right"

Page 41: Android Development Course in HSE lecture #3

Resources for multiple screens

● drawable● drawable-xhdpi● drawable-hdpi● drawable-mdpi● layout● layout-land

Page 43: Android Development Course in HSE lecture #3

External jars Хранить в папке libs!

Page 46: Android Development Course in HSE lecture #3

Homework

● Activity Lifecycle● Views and Layouts


Recommended