콘텐츠로 건너뛰기

자주 방문한 페이지

최근 방문한 페이지

navigation

Activity State Changes

Different events, some user-triggered and some system-triggered, can cause an Activity to transition from one state to another. This document describes some common cases in which such transitions happen, and how to handle those transitions.

For more information about activity states, see The Activity Lifecycle.

Configuration change occurs

There are a number of events that can trigger a configuration change. Perhaps the most prominent example is a change between portrait and landscape orientations. Other cases that can cause configuration changes include changes to language or input device.

When a configuration change occurs, the activity is destroyed and recreated. To preserve simple transient-state data for the activity, you must override the onSaveInstanceState() method to save the data, and then use onCreate() or onRestoreInstanceState() callbacks to recreate the instance state.

For specific detail about persisting simple data across configuration changes, see the Saving and restoring activity state section of The Activity Lifecycle. For more information about approaches to persisting both simple and complex UI data, see Saving UI States.

Handling multi-window cases

When an app enters multi-window mode, available in Android 7.0 (API level 24)and higher, the system notifies the currently running activity of a configuration change, thus going through the lifecycle transitions described above. This behavior also occurs if an app already in multi-window mode gets resized. Your activity can handle the configuration change itself, or it can allow the system to destroy the activity and recreate it with the new dimensions.

For more information about the multi-window lifecycle, see the Multi-Window Lifecycle section of the Multi-Window Support page.

In multi-window mode, although there are two apps that are visible to the user, only the one with which the user is interacting is in the foreground and has focus. That activity is in the Resumed state, while the app in the other window is in the Paused state.

When the user switches from app A to app B, the system calls onPause() on app A, and onResume() on app B. It switches between these two methods each time the user toggles between apps.

For more detail about multi-windowing, refer to Multi-Window Support.

Activity or dialog appears in foreground

If a new activity or dialog appears in the foreground, taking focus and partially covering the activity in progress, the covered activity loses focus and enters the Paused state. Then, the system calls onResume() on it.

When the covered activity returns to the foreground and regains focus, it calls onResume().

If a new activity or dialog appears in the foreground, taking focus and completely covering the activity in progress, the covered activity loses focus and enters the Stopped state. The system then, in rapid succession, calls onPause() and onStop().

When the same instance of the covered activity comes back to the foreground, the system calls onRestart(), onStart(), and onResume() on the activity. If it is a new instance of the covered activity that comes to the background, the system does not call onRestart(), only calling onStart() and onResume().

Note: When the user taps the Overview or Home button, the system behaves as if the current activity has been completely covered.

User taps Back button

If an activity is in the foreground, and the user taps the Back button, the activity transitions through the onPause(), onStop(), and onDestroy() callbacks. In addition to being destroyed, the activity is also removed from the back stack.

It is important to note that, by default, the onSaveInstanceState() callback does not fire in this case. This behavior is based on the assumption that the user tapped the Back button with no expectation of returning to the same instance of the activity. However, you can override the onBackPressed() method to implement some custom behavior, for example a “confirm-quit" dialog.

If you override the onBackPressed() method, we still highly recommend that you invoke super.onBackPressed() from your overridden method. Otherwise the Back button behavior may be jarring to the user.

이 사이트는 쿠키를 사용하여 사이트별 언어 및 표시 옵션에 대한 환경설정을 저장합니다.

Google Play에서 성공을 거두는 데 도움이 되는 최신 Android 개발자 뉴스 및 도움말을 받아 보세요.

* 필수 입력란

완료되었습니다.

WeChat에서 Google Developers 팔로우하기

이 사이트를 (으)로 탐색할까요?

페이지를 요청했지만 이 사이트의 언어 환경설정은 입니다.

언어 환경설정을 변경하고 이 사이트를 (으)로 탐색할까요? 언어 환경설정을 나중에 변경하려면 각 페이지 하단의 언어 메뉴를 사용하세요.

이 클래스를 사용하려면 API 수준 이상이 필요합니다.

문서에 대해 선택한 API 수준이 이므로 이 문서가 표시되지 않습니다. 왼쪽 탐색 메뉴의 선택기로 문서 API 수준을 변경할 수 있습니다.

앱에 필요한 API 수준 지정에 관한 자세한 내용은 다양한 플랫폼 버전 지원을 참조하세요.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)