Created
January 28, 2022 02:59
-
-
Save mr5z/a3ed946d869cb86615cbbe71e114723c to your computer and use it in GitHub Desktop.
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
// interface | |
interface IActivityInstanceProvider { | |
fun updateInstance(activity: Activity) | |
fun <TActivity: Activity> get(): TActivity? | |
} | |
// class | |
class ActivityInstanceProvider: IActivityInstanceProvider { | |
private val activityInstance: HashSet<WeakReference<Activity?>> = hashSetOf() | |
override fun updateInstance(activity: Activity) { | |
activityInstance.add(WeakReference(activity)) | |
} | |
override fun <TActivity: Activity> get(): TActivity? { | |
val ref = activityInstance.firstOrNull() { it.javaClass == TActivity::class } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/mr5z/a3ed946d869cb86615cbbe71e114723c#file-instanceprovider-kt-L9
This suck ass