kotlin 的 Application 单例模式

2019-10-18  本文已影响0人  kot_flu
class NewsApplication : Application() {
private var sqlHelper: SQLHelper? = null

    /** 获取数据库Helper  */
    fun getSQLHelper(): SQLHelper {
        if (sqlHelper == null) {
            sqlHelper = SQLHelper(instance)
        }
        return sqlHelper as SQLHelper
    }

    companion object {
        var isIsLogin = false
        //获取单例
        @JvmStatic lateinit  var instance: SportsApplication
            private set
    }
}


//调用
SportsApplication.getInstance()
SportsApplication.getInstance().getSQLHelper()

上一篇下一篇

猜你喜欢

热点阅读