Android(Kotlin)

Android ViewModel Context

----___<<<<< 2022. 10. 20. 09:19

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.bokchi.viewmodelcontext">

    <application
        android:name=".App"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ViewModelContext"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

class App : Application() {

    init {
        instance = this
    }

    companion object {

        private var instance: App? = null

        fun context() : Context {
            return instance!!.applicationContext
        }
    }

}

 

 

 

 

 

- 참조

 

https://dreamaz.tistory.com/53

 

[안드로이드] <application>의 android:name

안녕하세요. 개발자 드리머즈입니다.           android:name=".common.GlobalApplication"        android:allowBackup="false"        android:icon="@drawable/kakaolink_sample_icon"  ..

dreamaz.tistory.com

 

https://ddangeun.tistory.com/78

 

[안드로이드] application context 어디서나 쉽게 가져오기 ― companion object에서 context 사용

Manifest 추가 android:name=".MyApplication" application에 위의 코드를 추가합니다. ... MyApplication class Java MyApplication.java public class MyApplication extends Application { private static Cont..

ddangeun.tistory.com

 

'Android(Kotlin)' 카테고리의 다른 글

Andorid AlarmManager  (0) 2022.10.29
Android Shimmer  (0) 2022.10.22
Android BOOT_COMPLETED  (0) 2022.10.20
Simple ForegroundService  (0) 2022.10.15
Android ROOM sqlcipher  (0) 2022.09.20