Presentation is loading. Please wait.

Presentation is loading. Please wait.

Activity 생명주기 UNIT 13 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Logcat 액티비티 생명주기를 설명할 수 있다. 현재 상태를 저장할 수 있다. 2.

Similar presentations


Presentation on theme: "Activity 생명주기 UNIT 13 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Logcat 액티비티 생명주기를 설명할 수 있다. 현재 상태를 저장할 수 있다. 2."— Presentation transcript:

1 Activity 생명주기 UNIT 13 로봇 SW 콘텐츠 교육원 조용수

2 학습 목표 Logcat 액티비티 생명주기를 설명할 수 있다. 현재 상태를 저장할 수 있다. 2

3 로그캣 Window > Show View > Other… 3

4 로그캣 4 로그 레벨 verbose, debug, info, warn, error, assert 저장로그 모두 삭제일시 멈춤

5 로그 레벨 verbose – 배포용 패키지 만들 때 컴파일 단계에서 빠짐 debug – 컴파일은 되지만 런타임 시에 빠짐 info warn error assert – 절대로 일어나서는 안 되는 치명적인 오류 5

6 로그캣 6 필터 추가 필터 삭제필터 편집

7 Log public static int v (String tag, String msg) public static int d (String tag, String msg) public static int i (String tag, String msg) public static int w (String tag, String msg) public static int e (String tag, String msg) public static int wtf (String tag, String msg) 7

8 Log 8 public class MainActivity extends RobotActivity { private Device leftWheelDevice; private Device rightWheelDevice; private MicThread thread; private static final String TAG = "Example"; @Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); thread = new MicThread(); thread.start(); } @Override protected void onDestroy() { Log.v(TAG, "onDestroy"); super.onDestroy(); if(thread != null) thread.cancel(); }

9 Log 9 private class MicThread extends Thread { private static final int FREQ = 44100; private static final int CHANNEL = AudioFormat.CHANNEL_IN_MONO; private static final int ENCODING = AudioFormat.ENCODING_PCM_16BIT; private boolean running = true; @Override public void run() { Log.v(TAG, "thread started");... while(running) {... }... Log.v(TAG, "thread finished"); } void cancel() { Log.v(TAG, "cancel"); running = false; }

10 액티비티 생명주기 10 액티비티 상태 – 실행 – 일시 정지 – 정지

11 액티비티 생명주기 11

12 액티비티 생명주기 화면이 회전하는 경우 12 onCreate 회전 onStart onResume onSaveInstanceState onPause onStop onDestroy onRestoreInstanceState onCreate onStart onResume

13 액티비티 생명주기 Home 키 누른 후 앱 다시 실행 13 onCreate Home 키 onStart onResume onSaveInstanceState onPause onStop onRestart onStart onResume 다시 실행

14 액티비티 생명주기 Back 키를 누른 경우 14 onCreate Back 키 onStart onResume finish onPause onStop onDestroy onBackPressed

15 액티비티 생명주기 15 public class MainActivity extends Activity { private static final String TAG = "Example"; @Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override protected void onDestroy() { Log.v(TAG, "onDestroy"); super.onDestroy(); }

16 액티비티 생명주기 16 @Override protected void onResume() { Log.v(TAG, "onResume"); super.onResume(); } @Override protected void onPause() { Log.v(TAG, "onPause"); super.onPause(); } @Override protected void onStart() { Log.v(TAG, "onStart"); super.onStart(); } @Override protected void onStop() { Log.v(TAG, "onStop"); super.onStop(); }

17 액티비티 생명주기 17 @Override protected void onRestart() { Log.v(TAG, "onRestart"); super.onRestart(); } @Override protected void onSaveInstanceState(Bundle outState) { Log.v(TAG, "onSaveInstanceState"); super.onSaveInstanceState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { Log.v(TAG, "onRestoreInstanceState"); super.onRestoreInstanceState(savedInstanceState); }

18 액티비티 생명주기 18 @Override public void onBackPressed() { Log.v(TAG, "onBackPressed"); super.onBackPressed(); } @Override public void finish() { Log.v(TAG, "finish"); super.finish(); }

19 현재 상태 저장 19 private Button button; @Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { button.setText(R.string.clicked); } }); }

20 현재 상태 저장 20 @Override protected void onSaveInstanceState(Bundle outState) { Log.v(TAG, "onSaveInstanceState"); super.onSaveInstanceState(outState); String text = button.getText().toString(); outState.putString("ButtonText", text); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { Log.v(TAG, "onRestoreInstanceState"); super.onRestoreInstanceState(savedInstanceState); button.setText(savedInstanceState.getString("ButtonText")); }

21 번들 (Bundle) –void putBoolean(String key, boolean value) –void putBooleanArray(String key, boolean[] value) –void putByte(String key, byte value) –void putByteArray(String key, byte[] value) –void putChar(String key, char value) –void putCharArray(String key, char[] value) –void putShort(String key, short value) –void putShortArray(String key, short[] value) –void putInt(String key, int value) –void putIntArray(String key, int[] value) –void putLong(String key, long value) –void putLongArray(String key, long[] value) –void putFloat(String key, float value) –void putFloatArray(String key, float[] value) –void putDouble(String key, double value) –void putDoubleArray(String key, double[] value) –void putString(String key, String value) –void putStringArray(String key, String[] value) –void putCharSequence(String key, CharSequence value) –void putCharSequenceArray(String key, CharSequence[] value) –… 21 Bundle Object

22 번들 (Bundle) –boolean getBoolean(String key) –byte getByte(String key) –char getChar(String key) –short getShort(String key) –int getInt(String key) –long getLong(String key) –float getFloat(String key) –double getDouble(String key) –String getString(String key) –CharSequence getCharSequence(String key) –… 22 –boolean getBoolean(String key, boolean defaultValue) –byte getByte(String key, byte defaultValue) –char getChar(String key, char defaultValue) –short getShort(String key, short defaultValue) –int getInt(String key, int defaultValue) –long getLong(String key, long defaultValue) –float getFloat(String key, float defaultValue) –double getDouble(String key, double defaultValue) –String getString(String key, String defaultValue) –CharSequence getCharSequence(String key, CharSequence defaultValue) –… –byte[] getByteArray(String key) –char[] getCharArray(String key) –short[] getShortArray(String key) –int[] getIntArray(String key) –long[] getLongArray(String key) –float[] getFloatArray(String key) –double[] getDoubleArray(String key) –String[] getStringArray(String key) –CharSequence[] getCharSequenceArray(String key) –…

23 리소스 23 layout-land layout-port

24 리소스 폴더 MCC(mobile country code) and MNC(mobile network code): mcc310-mnc004 Language and region: en, fr, en-rUS, fr-rFR, fr-rCA, ko Layout direction: ldrtl, ldltr Smallest width: sw320dp, sw720dp Available width: w720dp, w1024dp Available height: h720dp, h1024dp Screen size: small, normal, large, xlarge Screen aspect: long, notlong Screen orientation: port, land UI mode: car, desk, television, appliance Night mode: night, notnight Screen pixel density: ldpi, mdpi, hdpi, xhdpi, xxhdpi, nodpi, tvdpi Touchscreen type: notouch, finger Keyboard availability: keysexposed, keyshidden, keyssoft Primary text input method: nokeys, qwerty, 12key Navigation key availability: navexposed, navhidden Primary non-touch navigation method: nonav, dpad, trackball, wheel Platform version: v3, v7 24

25 configChanges 25 onCreate 회전 onStart onResume onConfigurationChanged <activity android:name="com.example.unit16.MainActivity" android:label="@string/app_name" android:configChanges="orientation|screenSize" > @Override public void onConfigurationChanged(Configuration newConfig) { Log.v(TAG, "onConfigurationChanged"); super.onConfigurationChanged(newConfig); }


Download ppt "Activity 생명주기 UNIT 13 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Logcat 액티비티 생명주기를 설명할 수 있다. 현재 상태를 저장할 수 있다. 2."

Similar presentations


Ads by Google