From eb98dc0826c04b60b1d03797f54de01630eb55c7 Mon Sep 17 00:00:00 2001 From: yimiao Date: Tue, 3 Aug 2021 11:19:19 +0800 Subject: [PATCH] =?UTF-8?q?desc:=E6=9B=BF=E6=8D=A2CommonApplication?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F=20author:wangyimi?= =?UTF-8?q?ao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/common/commonlibtest/MyApplication.kt | 4 +--- .../java/com/common/commonlib/CommonApplication.kt | 14 ++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/common/commonlibtest/MyApplication.kt b/app/src/main/java/com/common/commonlibtest/MyApplication.kt index a0a8f4e..8a96353 100644 --- a/app/src/main/java/com/common/commonlibtest/MyApplication.kt +++ b/app/src/main/java/com/common/commonlibtest/MyApplication.kt @@ -1,15 +1,13 @@ package com.common.commonlibtest -import android.app.Application import com.common.commonlib.CommonApplication import com.common.commonlib.image.config.GlideBaseConfig import com.common.commonlib.image.loader.ImageLoader -class MyApplication : Application() { +class MyApplication : CommonApplication() { override fun onCreate() { super.onCreate() - CommonApplication.intLibs(this) ImageLoader.init(this, GlideBaseConfig.MemoryType.NORMAL) } } \ No newline at end of file diff --git a/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt b/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt index 4165b13..dce1cd9 100644 --- a/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt +++ b/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt @@ -11,19 +11,21 @@ import android.content.Context * @since 2021/7/28 */ @SuppressLint("StaticFieldLeak") -object CommonApplication : Application() { - private var commonContext: Context? = null - +open class CommonApplication : Application() { override fun onCreate() { super.onCreate() intLibs(this) } - fun intLibs(context: Context) { + private fun intLibs(context: Context) { commonContext = context } - fun getContext(): Context? { - return commonContext + companion object { + private var commonContext: Context? = null + + fun getContext(): Context? { + return commonContext + } } } \ No newline at end of file