Keep the screen awake throughout my activity

后端 未结 5 1173
说谎
说谎 2020-12-04 21:03

I have three activities in my app. I want to keep the screen awake when it is in the second activity. The screen should not go off in my second activity unless the \"lock\"

5条回答
  •  温柔的废话
    2020-12-04 21:33

    This code is deprecated, use this instead:

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
    wl.acquire();
    

    After you finish with usage, call (best solution is to call this method in onDestroy method of some activity):

    wl.release();
    

    More about this on this link

提交回复
热议问题