투케이2K

802. (Android/Java) onConfigurationChanged 메소드 재정의 및 안드로이드 액티비티 화면 회전 상태 감지 - orientation 본문

Android

802. (Android/Java) onConfigurationChanged 메소드 재정의 및 안드로이드 액티비티 화면 회전 상태 감지 - orientation

투케이2K 2024. 5. 24. 09:12

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : Java / Kotlin

 

[소스 코드]

    // -----------------------------------------------------------------------------------------
    // [AndroidManifest.xml 파일] : android:configChanges 속성 설정
    // -----------------------------------------------------------------------------------------
        <activity
            android:name=".A_Intro"
            android:exported="true"
            android:windowSoftInputMode="adjustPan"

            android:configChanges="keyboardHidden|orientation|screenSize">

        </activity>



    // -----------------------------------------------------------------------------------------
    // [Java] : [액티비티 상태 변경 상태 확인] : [ex] : android:configChanges="keyboardHidden|orientation|screenSize"
    // -----------------------------------------------------------------------------------------
    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        
        // [화면 전환 상태 감지]
        if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            S_Log._W_("onConfigurationChanged :: PORTRAIT", new String[]{
                    "screenWidthDp :: " + String.valueOf(newConfig.screenWidthDp),
                    "screenHeightDp :: " + String.valueOf(newConfig.screenHeightDp)
            });
        }
        else{
            S_Log._W_("onConfigurationChanged :: LANDSCAPE", new String[]{
                    "screenWidthDp :: " + String.valueOf(newConfig.screenWidthDp),
                    "screenHeightDp :: " + String.valueOf(newConfig.screenHeightDp)
            });
        }
    }
 

[결과 출력]

 

W///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.javaproject.A_Intro.onConfigurationChanged(A_Intro.java:616)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2024-05-23 16:09:16 목요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: onConfigurationChanged :: LANDSCAPE]
I/: ----------------------------------------------------
I/: [LOG :: screenWidthDp :: 758]
I/: ----------------------------------------------------
I/: [LOG :: screenHeightDp :: 360]
W///===========//: ================================================


W///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.javaproject.A_Intro.onConfigurationChanged(A_Intro.java:610)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2024-05-23 16:09:31 목요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: onConfigurationChanged :: PORTRAIT]
I/: ----------------------------------------------------
I/: [LOG :: screenWidthDp :: 384]
I/: ----------------------------------------------------
I/: [LOG :: screenHeightDp :: 758]
W///===========//: ================================================

 

반응형
Comments