I have a simple app that uses a player as a Singleton.
@JvmStatic
fun getInstance(context: Context): MyPlayer {
return INSTANCE ?: synchronized(this) {
MyPlayer(context).also {
INSTANCE = it
}
}
}
In Activity A I assign a local field to a player instance using
val player = MyPlayer.getInstance(appContext)
In Activity B after some action, I want to release the player and null out the instance. In MyPlayer class I set:
INSTANCE = null
When I go back to Activity A, the player field still has a reference to the player and it's not null.
What am I missing here?
Note: Activity A written in Java, MyPlayer in Kotlin (if it matters)