Skip to content

Commit

Permalink
fix: add debug statements when a fragment lifecycle callback is not r…
Browse files Browse the repository at this point in the history
…egistered
  • Loading branch information
PouriaAmini committed Aug 22, 2024
1 parent 0baa708 commit 70d4924
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ internal object FragmentActivityHandler {
val callback = AutocaptureFragmentLifecycleCallbacks(track, logger)
supportFragmentManager.registerFragmentLifecycleCallbacks(callback, false)
callbacksMap.getOrPut(this) { mutableListOf() }.add(callback)
}
} ?: logger.debug("Activity is not a FragmentActivity")
}

fun Activity.unregisterFragmentLifecycleCallbacks() {
fun Activity.unregisterFragmentLifecycleCallbacks(logger: Logger) {
(this as? FragmentActivity)?.apply {
callbacksMap.remove(this)?.let { callbacks ->
for (callback in callbacks) {
supportFragmentManager.unregisterFragmentLifecycleCallbacks(callback)
}
}
}
} ?: logger.debug("Activity is not a FragmentActivity")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DefaultEventUtils(private val amplitude: Amplitude) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
LoadClass.isClassAvailable(FRAGMENT_ACTIVITY_CLASS_NAME, amplitude.logger)
) {
activity.unregisterFragmentLifecycleCallbacks()
activity.unregisterFragmentLifecycleCallbacks(amplitude.logger)
}
}

Expand Down

0 comments on commit 70d4924

Please sign in to comment.