OnPause and OnStop() called immediately after starting activity

后端 未结 7 2019
鱼传尺愫
鱼传尺愫 2020-12-04 11:04

I have an activity that needs to turn screen on(if offed) when it is started. So in onCreate, I have:

this.getWindow().setFlags(
            WindowManager.La         


        
7条回答
  •  被撕碎了的回忆
    2020-12-04 11:58

    The workaround by Manish Mulimani worked for me, except I first check for the window focus and then call through to the super.onPause():

    public void onPause() {
        mFocusDuringOnPause = hasWindowFocus();    
        super.onPause();
    }
    
    public void onStop() {
        super.onStop();
        if (mFocusDuringOnPause) {
            // normal scenario
        } else {
            // activity was started when screen was off or screen was on with keyguard displayed
        }
    }
    

提交回复
热议问题