diff --git a/panel-core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt b/panel-core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt index 79030da..c012788 100644 --- a/panel-core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt +++ b/panel-core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt @@ -11,7 +11,7 @@ import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow -internal class DebugPanelInstance constructor( +internal class DebugPanelInstance( application: Application, plugins: List = emptyList() ) { diff --git a/panel-core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt b/panel-core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt index 51b2a63..c7fac3c 100644 --- a/panel-core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt +++ b/panel-core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt @@ -5,10 +5,10 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.redmadrobot.debug.core.DebugPanel +import java.lang.ref.WeakReference -internal class DebugPanelBroadcastReceiver( - private val activity: Activity -) : BroadcastReceiver() { +internal class DebugPanelBroadcastReceiver(activity: Activity) : BroadcastReceiver() { + private val activityReference = WeakReference(activity) companion object { const val ACTION_OPEN_DEBUG_PANEL = "com.redmadrobot.debug.core.ACTION_OPEN_DEBUG_PANEL" @@ -16,7 +16,7 @@ internal class DebugPanelBroadcastReceiver( override fun onReceive(context: Context, intent: Intent) { if (intent.action == ACTION_OPEN_DEBUG_PANEL) { - DebugPanel.showPanel(activity) + activityReference.get()?.let { DebugPanel.showPanel(it) } } } } diff --git a/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt b/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt index c16dfd6..c70a75b 100644 --- a/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt +++ b/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt @@ -14,9 +14,6 @@ import com.redmadrobot.debug_sample.network.ApiFactory import com.redmadrobot.debugpanel.databinding.ActivityMainBinding import com.redmadrobot.flipper.config.FlipperValue import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import okhttp3.ResponseBody @@ -146,8 +143,7 @@ class MainActivity : AppCompatActivity() { .onEach { changedToggles -> onFlipperTogglesChanged(changedToggles) } - .flowOn(Dispatchers.Main) - .launchIn(GlobalScope) + .launchIn(lifecycleScope) } private fun onFlipperTogglesChanged(changedToggles: Map) {