Notice
Recent Posts
Recent Comments
Link
투케이2K
434. (kotlin/코틀린) Application 애플리케이션 클래스 ActivityLifecycleCallbacks 상속 받은 후 Activity 액티비티 라이프 사이클 감지 본문
Kotlin
434. (kotlin/코틀린) Application 애플리케이션 클래스 ActivityLifecycleCallbacks 상속 받은 후 Activity 액티비티 라이프 사이클 감지
투케이2K 2023. 11. 14. 19:53[개발 환경 설정]
개발 툴 : AndroidStudio
개발 언어 : Kotlin
[소스 코드]
package com.example.kotlinproject
import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Bundle
class A_Application : Application(), Application.ActivityLifecycleCallbacks {
/**
* // --------------------------------------------------------------------------------------
* TODO [클래스 설명]
* // --------------------------------------------------------------------------------------
* 1. 애플리케이션 프로세스 관리 클래스
* // --------------------------------------------------------------------------------------
* 2. AndroidManifest.xml 파일에서 application 부분에 등록 필요
*
* <application
* android:name="com.example.testapp.A_Application"
* </application>
* // --------------------------------------------------------------------------------------
* */
/**
* // --------------------------------------------------------------------------------------
* // TODO [빠른 로직 찾기 : 주석 로직 찾기]
* // --------------------------------------------------------------------------------------
* // [SEARCH FAST] : []
* // --------------------------------------------------------------------------------------
*
* // --------------------------------------------------------------------------------------
*
* // --------------------------------------------------------------------------------------
*
* // --------------------------------------------------------------------------------------
*
* // --------------------------------------------------------------------------------------
* */
// --------------------------------------------------------------------------------------
// TODO [companion object >> static 선언 실시]
// --------------------------------------------------------------------------------------
companion object {
// ----------------------------------------------------------------------------------
// TODO [전역 변수]
// ----------------------------------------------------------------------------------
val ACTIVITY_NAME = "A_Application"
} // [companion 종료]
// -----------------------------------------------------------------------------------------
// TODO [프로세스 생명주기 관리]
// -----------------------------------------------------------------------------------------
override fun attachBaseContext(base: Context) {
try {
super.attachBaseContext(base)
// ===============================================================
S_Log._D_(S_FinalMsg.LOG_Application_attachBaseContext, null)
// ===============================================================
}
catch (e: Exception) {
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
}
// -----------------------------------------------------------------------------------------
// TODO [프로세스 생명주기 관리]
// -----------------------------------------------------------------------------------------
override fun onCreate() {
try {
super.onCreate()
// ===============================================================
// [앱 최초 실행 시 로그 파일 초기화]
// ===============================================================
S_Log._F_(applicationContext, ACTIVITY_NAME + " : " + S_FinalMsg.LOG_Application_onCreate + " : " + C_Util.getSourceCodeLine(), null)
// ---------------------------------------------------------------
// [액티비티 라이프 사이클 상태 감지 등록]
// ---------------------------------------------------------------
try {
registerActivityLifecycleCallbacks(this)
} catch (e: Exception) {
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
// ---------------------------------------------------------------
// [작업 태스크 날림 이벤트 서비스 개시]
// ---------------------------------------------------------------
try {
startService(Intent(applicationContext, S_ProgramTaskService :: class.java))
}
catch (e: Exception){
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// [애플리케이션 시작 시 데이터 초기화 실시]
// ---------------------------------------------------------------
// S_Preference.proccessCreateClear(applicationContext)
// ---------------------------------------------------------------
}
catch (e: Exception) {
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
}
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onCreate 확인]
// -----------------------------------------------------------------------------------------
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
try {
S_Log._D_(S_FinalMsg.LOG_Application_Activity_Lifecycle + " :: " + activity.localClassName.toString() + " :: Created", null)
}
catch (e : Exception){
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
}
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onStarted 확인]
// -----------------------------------------------------------------------------------------
override fun onActivityStarted(activity: Activity) { }
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onResumed 확인]
// -----------------------------------------------------------------------------------------
override fun onActivityResumed(activity: Activity) {
try {
S_Log._W_(S_FinalMsg.LOG_Application_Activity_Lifecycle + " :: " + activity.localClassName.toString() + " :: Resumed", null)
}
catch (e : Exception){
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
}
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onPaused 확인]
// -----------------------------------------------------------------------------------------
override fun onActivityPaused(activity: Activity) {
try {
S_Log._E_(S_FinalMsg.LOG_Application_Activity_Lifecycle + " :: " + activity.localClassName.toString() + " :: Paused", null)
}
catch (e : Exception){
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
}
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onStopped 확인]
// -----------------------------------------------------------------------------------------
override fun onActivityStopped(activity: Activity) { }
// -----------------------------------------------------------------------------------------
// TODO [액티비티 InstanceState 확인]
// -----------------------------------------------------------------------------------------
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { }
// -----------------------------------------------------------------------------------------
// TODO [액티비티 Destroyed 확인]
// -----------------------------------------------------------------------------------------
override fun onActivityDestroyed(activity: Activity) {
try {
S_Log._E_(S_FinalMsg.LOG_Application_Activity_Lifecycle + " :: " + activity.localClassName.toString() + " :: Destroyed", null)
}
catch (e : Exception){
S_Log._printStackTrace_(null, S_FinalMsg.LOG_BUG_STATE, null, e)
}
}
} // TODO [클래스 종료]
[결과 출력]
D///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Application.onActivityCreated(A_Application.kt:164)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-11-14 08:21:06 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: 애플리케이션 >> 액티비티 :: 라이프 사이클 감지 :: A_Intro :: Created]
D///===========//: ================================================
D///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Intro.onCreate(A_Intro.kt:81)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-11-14 08:21:06 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: 액티비티 수행 실시]
D///===========//: ================================================
반응형
'Kotlin' 카테고리의 다른 글
Comments