안녕 하세요 버섯돌이 유재성입니다.
안드로이드 앱을 만들때 가장 중요한것 중 하나가 액티비티의 라이프 사이클입니다.
아래 사이트에서 라이프 사이클과 관련된 강좌가 있으니 참고 하시기 바라며, 그 중 일부 내용을 발췌합니다.
출처 : http://developer.android.com/training/basics/activity-lifecycle/starting.html
Understand the Lifecycle Callbacks
Depending on the complexity of your activity, you probably don't need to implement all the lifecycle methods. However, it's important that you understand each one and implement those that ensure your app behaves the way users expect. Implementing your activity lifecycle methods properly ensures your app behaves well in several ways, including that it:
- Does not crash if the user receives a phone call or switches to another app while using your app.
- Does not consume valuable system resources when the user is not actively using it.
- Does not lose the user's progress if they leave your app and return to it at a later time.
- Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation.
As you'll learn in the following lessons, there are several situations in which an activity transitions between different states that are illustrated in figure 1. However, only three of these states can be static. That is, the activity can exist in one of only three states for an extended period of time:
- Resumed
- In this state, the activity is in the foreground and the user can interact with it. (Also sometimes referred to as the "running" state.)
- Paused
- In this state, the activity is partially obscured by another activity—the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen. The paused activity does not receive user input and cannot execute any code.
- Stopped
- In this state, the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.
The other states (Created and Started) are transient and the system quickly moves from them to the next state by calling the next lifecycle callback method. That is, after the system calls onCreate()
, it quickly callsonStart()
, which is quickly followed by onResume()
.
Note: The onCreate()
method includes a parameter called savedInstanceState
that's discussed in the latter lesson about Recreating an Activity.
Note: When your activity receives a call to onPause()
, it may be an indication that the activity will be paused for a moment and the user may return focus to your activity. However, it's usually the first indication that the user is leaving your activity.
The Activity
class provides two lifecycle methods, onStop()
and onRestart()
, which allow you to specifically handle how your activity handles being stopped and restarted. Unlike the paused state, which identifies a partial UI obstruction, the stopped state guarantees that the UI is no longer visible and the user's focus is in a separate activity (or an entirely separate app).
Note: Because the system retains your Activity
instance in system memory when it is stopped, it's possible that you don't need to implement the onStop()
and onRestart()
(or even onStart()
methods at all. For most activities that are relatively simple, the activity will stop and restart just fine and you might only need to use onPause()
to pause ongoing actions and disconnect from system resources.
Note: In order for the Android system to restore the state of the views in your activity, each view must have a unique ID, supplied by the android:id
attribute.
To save additional data about the activity state, you must override the onSaveInstanceState()
callback method. The system calls this method when the user is leaving your activity and passes it the Bundle
object that will be saved in the event that your activity is destroyed unexpectedly. If the system must recreate the activity instance later, it passes the same Bundle
object to both the onRestoreInstanceState()
andonCreate()
methods.
'Android' 카테고리의 다른 글
[추천] Android의 HTTP 클라이언트 라이브러리 (0) | 2014.11.23 |
---|---|
[펌] 개선된 Pull To Refresh 라이브러리, Android Pull To Refresh 라이브러리 (0) | 2014.11.23 |
[추천][Site] Android 기초 강좌 - 안드로이드 사이트의 Training 목차 (0) | 2014.11.23 |
[버섯] Media Playback - 안드로이드에서 RTSP 플레이어 개발 관련 (0) | 2014.11.23 |
[버섯] 안드로이드 버전별 코드 네임 및 빌드 넘버들(Codenames, Tags, and Build Numbers) (0) | 2014.11.23 |