You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
Kotlin
57 lines
1.2 KiB
Kotlin
2 years ago
|
package com.common.commonlib
|
||
|
|
||
|
import android.annotation.SuppressLint
|
||
|
import android.app.Application
|
||
|
import android.content.Context
|
||
|
import androidx.lifecycle.Lifecycle
|
||
|
import androidx.lifecycle.LifecycleObserver
|
||
|
import androidx.lifecycle.OnLifecycleEvent
|
||
|
import androidx.lifecycle.ProcessLifecycleOwner
|
||
|
import com.common.commonlib.utils.BaseUtils
|
||
|
import com.tencent.mmkv.MMKV
|
||
|
|
||
|
/**
|
||
|
* 基础Application
|
||
|
*
|
||
|
* @author wangym
|
||
|
* @since 2021/7/28
|
||
|
*/
|
||
|
@SuppressLint("StaticFieldLeak")
|
||
|
open class CommonApplication : Application(), LifecycleObserver {
|
||
|
override fun onCreate() {
|
||
|
super.onCreate()
|
||
|
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||
|
intLibs(this)
|
||
|
}
|
||
|
|
||
|
private fun intLibs(context: Context) {
|
||
|
commonContext = context
|
||
|
|
||
|
// 初始化MMKV
|
||
|
MMKV.initialize(this)
|
||
|
|
||
|
initNet()
|
||
|
}
|
||
|
|
||
|
private fun initNet() {
|
||
|
BaseUtils.enableFullLog()
|
||
|
}
|
||
|
|
||
|
companion object {
|
||
|
private var commonContext: Context? = null
|
||
|
|
||
|
fun getContext(): Context? {
|
||
|
return commonContext
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||
|
open fun onAppForeground(){
|
||
|
|
||
|
}
|
||
|
|
||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||
|
open fun onAppBackground(){
|
||
|
|
||
|
}
|
||
|
}
|