Last active
September 14, 2018 12:51
-
-
Save ValeryPonomarenko/9565a69f17c975a5f8bc31451d327f40 to your computer and use it in GitHub Desktop.
Lifecycle aware dagger components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class ActivityLifecycleHelper( | |
private val componentsStore: ComponentsStore | |
) : Application.ActivityLifecycleCallbacks { | |
override fun onActivityPaused(activity: Activity) {} | |
override fun onActivityResumed(activity: Activity) {} | |
override fun onActivityStarted(activity: Activity) {} | |
override fun onActivityDestroyed(activity: Activity) { | |
if (activity is IHasComponent && activity.isFinishing) { | |
componentsStore.remove(activity.getComponentKey()) | |
} | |
} | |
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) {} | |
override fun onActivityStopped(activity: Activity) {} | |
override fun onActivityCreated(activity: Activity, outState: Bundle?) { | |
if (activity is AppCompatActivity) { | |
activity.supportFragmentManager.registerFragmentLifecycleCallbacks( | |
FragmentLifecycleHelper(componentsStore), | |
true | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment