warning: [deprecation] FLAG_SHOW_WHEN_LOCKED in LayoutParams has been deprecated

Reference:

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED

This statement is deprecated from API level 27, so you can safely manage this situation with:

Adding the FLAG_SHOW_WHEN_LOCKED flag to the flags of the current window typically happens in the onCreate event and BEFORE the method SetContent() of an activity; after the deprecation, instead, you have to call the setShowWhenLocked(boolean) method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT < 27) // the old version
        getWindow()
            .addFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            );
    else  // the new version
         setShowWhenLocked(true);

    setContentView(R.layout.main_activity);
}

Leave a Reply

Your email address will not be published. Required fields are marked *