OnPause and OnStop() called immediately after starting activity

后端 未结 7 1999
鱼传尺愫
鱼传尺愫 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 12:04

    I've noticed there is activity attribute in the AndroidManifest.xml called android:showOnLockScreen="true|false"

    for example:

       <activity android:name="AlarmAlertFullScreen"
                    android:excludeFromRecents="true"
                    android:theme="@style/AlarmAlertFullScreenTheme"
                    android:showOnLockScreen="true"
                    android:screenOrientation="nosensor"
                    android:configChanges="orientation|screenSize|keyboardHidden|keyboard|navigation"/>
    

    I searched the web for its documentation but no luck, but from its name it should work as the Window flag WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED do.


    the only document I've found

    Specify that an Activity should be shown over the lock screen and, in a multiuser environment, across all users' windows [boolean]


    Edit

    can you please try to call your flag code before calling super.onCreate(...)

    public class BaseActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle bundle) {
        this.getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
            //then call super
            super.onCreate(bundle);
    .
    .
    .
      }
    }
    
    0 讨论(0)
提交回复
热议问题