[Fix]解决addObserver()不能运行在非主线程导致的crash问题
This commit is contained in:
@@ -83,6 +83,16 @@ object CallerVisualAngleManager {
|
||||
}
|
||||
|
||||
fun init(ctx: Context) {
|
||||
if (Thread.currentThread() != Looper.getMainLooper().thread) {
|
||||
scope.launch {
|
||||
initListen(ctx)
|
||||
}
|
||||
} else {
|
||||
initListen(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initListen(ctx: Context) {
|
||||
ctx.lifeCycleOwner.lifecycle.addObserver(object : LifecycleEventObserver {
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Event) {
|
||||
if (event == ON_DESTROY) {
|
||||
|
||||
Reference in New Issue
Block a user