Skip to content

Instantly share code, notes, and snippets.

@mr5z
Created January 28, 2022 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr5z/a3ed946d869cb86615cbbe71e114723c to your computer and use it in GitHub Desktop.
Save mr5z/a3ed946d869cb86615cbbe71e114723c to your computer and use it in GitHub Desktop.
// 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 }
}
}
@mr5z
Copy link
Author

mr5z commented Feb 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment