desc:替换CommonApplication的实现方式

author:wangyimiao
master
yimiao 3 years ago
parent 3982660340
commit eb98dc0826

@ -1,15 +1,13 @@
package com.common.commonlibtest package com.common.commonlibtest
import android.app.Application
import com.common.commonlib.CommonApplication import com.common.commonlib.CommonApplication
import com.common.commonlib.image.config.GlideBaseConfig import com.common.commonlib.image.config.GlideBaseConfig
import com.common.commonlib.image.loader.ImageLoader import com.common.commonlib.image.loader.ImageLoader
class MyApplication : Application() { class MyApplication : CommonApplication() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
CommonApplication.intLibs(this)
ImageLoader.init(this, GlideBaseConfig.MemoryType.NORMAL) ImageLoader.init(this, GlideBaseConfig.MemoryType.NORMAL)
} }
} }

@ -11,19 +11,21 @@ import android.content.Context
* @since 2021/7/28 * @since 2021/7/28
*/ */
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
object CommonApplication : Application() { open class CommonApplication : Application() {
private var commonContext: Context? = null
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
intLibs(this) intLibs(this)
} }
fun intLibs(context: Context) { private fun intLibs(context: Context) {
commonContext = context commonContext = context
} }
companion object {
private var commonContext: Context? = null
fun getContext(): Context? { fun getContext(): Context? {
return commonContext return commonContext
} }
}
} }
Loading…
Cancel
Save