투케이2K

709. (Android/Java) [간단 소스] instanceof 사용해 Context 타입이 특정 Activity 액티비티 인 지 확인 수행 본문

Android

709. (Android/Java) [간단 소스] instanceof 사용해 Context 타입이 특정 Activity 액티비티 인 지 확인 수행

투케이2K 2023. 12. 13. 17:20
반응형

[개발 환경 설정]

개발 툴 : AndroidStudio

 

[소스 코드]

        // ---------------------------------------------------------------
        // [로직 처리 실시]
        // ---------------------------------------------------------------
        try {

            Context mContext = A_Intro.this;

            if (mContext != null){ // [널 체크]

                if (mContext instanceof A_Webview){
                    S_Log._D_("Context Type :: A_Webview", null);
                }
                else if (mContext instanceof A_Intro){
                    S_Log._D_("Context Type :: A_Intro", null);
                }
                else {
                    S_Log._E_("Context Type :: 알 수 없음", null);
                }

            }

        }
        catch (Exception e){
            e.printStackTrace();
        }
 

[결과 출력]

 

D///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.javaproject.A_Intro.onCreate(A_Intro.java:317)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-12-12 14:29:14 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: Context Type :: A_Intro]
D///===========//: ================================================

 

반응형
Comments