Problem:
According to the README.md - "If your project is a single activity but uses Fragments for navigation, you can use the DebugMenuAttacher.attach method to your Activity.onCreate() to attach the debug menu to your whole application."
If the activity gets recreated for any reason, the old activity cannot be garbage collected because the previous reference doesn't allow it. Creating multiple activity instances and in our specific case, an unresponsive app.
DebugMenuAttacher.attach(
activity,
attach(activity) creates a ComposeView(activity) and adds it to the activity's decor view. Compose's internal AndroidComposeView retains a strong reference to the Activity context, apparently.
I tested around a bit locally with the library and adding a flag "fixed" the issue, and kind of confirmed that it is related.
@JvmStatic
fun attach(
activity: Activity,
modules: List<DebugMenuModule>,
showFab: Boolean = true,
enableShake: Boolean = false,
) = runCatching {
if (attached) return@runCatching
attached = true
Reproduction: Call DebugMenuAttacher.attach(activity) in onCreate() of a single-activity app. Switch dark/light mode twice via AppCompatDelegate.setDefaultNightMode().
Problem:
According to the README.md - "If your project is a single activity but uses Fragments for navigation, you can use the
DebugMenuAttacher.attachmethod to yourActivity.onCreate()to attach the debug menu to your whole application."If the activity gets recreated for any reason, the old activity cannot be garbage collected because the previous reference doesn't allow it. Creating multiple activity instances and in our specific case, an unresponsive app.
attach(activity) creates a ComposeView(activity) and adds it to the activity's decor view. Compose's internal AndroidComposeView retains a strong reference to the Activity context, apparently.
I tested around a bit locally with the library and adding a flag "fixed" the issue, and kind of confirmed that it is related.
Reproduction: Call DebugMenuAttacher.attach(activity) in onCreate() of a single-activity app. Switch dark/light mode twice via AppCompatDelegate.setDefaultNightMode().