android:keepScreenOn="true"를 사용하는 것은 FLAG_KEEP_SCREEN_ON를 사용하는 것과 동일합니다.
어떤 접근 방식이든 앱에 가장 최선인 방식을 사용하면 됩니다. 활동에 프로그래매틱 방식으로 플래그를 설정하는 것은 나중에 프로그래매틱 방식으로 플래그를 삭제하여 화면이 꺼지도록 선택할 수 있는 장점이 있습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Keep the screen on\n\nCertain apps need to keep the screen turned on, such as games or movie apps.\nSome Android APIs automatically keep the screen on for you. In other cases,\nyou can set a flag to manually keep the screen on.\n| **Note:** Keeping the device's screen on can drain the battery quickly. Ordinarily, you should let the device turn the screen off if the user is not interacting with it. If you do need to keep the screen on, do so for as short a time as possible.\n\nManually keep the screen on\n---------------------------\n\nTo keep the device's screen on, set the [`FLAG_KEEP_SCREEN_ON`](/reference/android/view/WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON) flag in your\nactivity. This flag may only be set in an activity, never in a service or other\napp component. For example: \n\n### Kotlin\n\n```kotlin\nclass MainActivity : Activity() {\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.activity_main)\n window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)\n }\n}\n```\n\n### Java\n\n```java\npublic class MainActivity extends Activity {\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);\n }\n}\n```\n\nAnother way to keep the screen on is by setting the\nthe [`android:keepScreenOn`](/reference/android/R.attr#keepScreenOn) attribute\nin your application's layout XML file: \n\n```xml\n\u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n android:keepScreenOn=\"true\"\u003e\n ...\n\u003c/RelativeLayout\u003e\n```\n\nUsing `android:keepScreenOn=\"true\"` is equivalent to using\n[`FLAG_KEEP_SCREEN_ON`](/reference/android/view/WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON).\nYou can use whichever approach is best for your app. The advantage of setting\nthe flag programmatically in your activity is that it gives you the option of\nprogrammatically clearing the flag later and thereby allowing the screen to turn\noff.\n\nIf an app with the `FLAG_KEEP_SCREEN_ON` flag goes into the background, the\nsystem allows the screen to turn off normally. You don't need to explicitly\nclear the flag in this case. If your app no longer needs to keep the screen on,\nyou should clear the flag. by calling\n[`clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)`](/reference/android/view/Window#clearFlags(int)).\n\n### Ambient Mode for TV\n\nOn TV devices, use [`FLAG_KEEP_SCREEN_ON`](/reference/android/view/WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON) to prevent the device from going\ninto [Ambient Mode](/training/tv/playback/ambient-mode) during active video playback. If the foreground activity\ndoes not set `FLAG_KEEP_SCREEN_ON`, the device automatically enters Ambient Mode\nafter a period of inactivity.\n\nSee also\n--------\n\n- [Keep the device awake](/develop/background-work/background-tasks/awake)\n- [Use wake locks](/develop/background-work/background-tasks/awake/wakelock)"]]