优化麦圈,泄漏处理
This commit is contained in:
@@ -29,6 +29,7 @@ import com.xscm.moduleutil.utils.CustomMsgCode
|
||||
import io.reactivex.disposables.Disposable
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
@@ -41,9 +42,20 @@ open class Application : CommonAppContext() {
|
||||
|
||||
var isAgoraStop = false
|
||||
var inviteDialog: InviteDialog? = null
|
||||
var currDialogActivity: Activity? = null
|
||||
|
||||
// 改为弱引用持有Activity
|
||||
private var mCurDialogActivityRef: WeakReference<Activity>? = null
|
||||
|
||||
fun setCurDialogActivity(activity: Activity?) {
|
||||
mCurDialogActivityRef = WeakReference(activity)
|
||||
}
|
||||
|
||||
fun getCurDialogActivity(): Activity? {
|
||||
if (mCurDialogActivityRef != null) {
|
||||
return mCurDialogActivityRef!!.get()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,6 +89,10 @@ open class Application : CommonAppContext() {
|
||||
// 初始化单例实例
|
||||
instance = this
|
||||
|
||||
|
||||
configureLeakCanary()
|
||||
|
||||
|
||||
// 初始化并预绘制视图 二卡八列
|
||||
WheatLayoutSingManager.init(this)
|
||||
WheatLayoutSingManager.getInstance().setWheatData(null)
|
||||
@@ -91,6 +107,15 @@ open class Application : CommonAppContext() {
|
||||
initImMsg()
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义 LeakCanary 配置(解决误报、优化检测规则)
|
||||
*/
|
||||
private fun configureLeakCanary() {
|
||||
// LeakCanary.config = LeakCanary.config.copy(
|
||||
// retainedVisibleThreshold = 3, // 对象被观察几次GC未被回收才认为泄漏 (默认5)
|
||||
// )
|
||||
}
|
||||
|
||||
private fun initImMsg() {
|
||||
MessageListenerSingleton.getInstance().setOnMsgTaskListener { event ->
|
||||
when (event.msgType) {
|
||||
@@ -240,7 +265,7 @@ open class Application : CommonAppContext() {
|
||||
fun showInviteDialog(activity: Activity?, t: IndexRecommendRoom) {
|
||||
if (isKeepScreenOn)
|
||||
return
|
||||
if (activity != null && activity == currDialogActivity && inviteDialog != null) {
|
||||
if (activity != null && activity == getCurDialogActivity() && inviteDialog != null) {
|
||||
inviteDialog?.setData(t)
|
||||
return
|
||||
}
|
||||
@@ -249,7 +274,7 @@ open class Application : CommonAppContext() {
|
||||
|
||||
inviteDialog = activity?.let { InviteDialog(it, t) }
|
||||
inviteDialog?.setData(t)
|
||||
currDialogActivity = activity
|
||||
setCurDialogActivity(activity)
|
||||
}
|
||||
|
||||
private fun initLogUtils() {
|
||||
|
||||
Reference in New Issue
Block a user