Is it allowed to put ActivityContext/ApplicationContext in a variable?
Please tell me is it allowed to put ActivityContext/ApplicationContext in a variable as shown in the code below?
class MainActivity : Activity() {
private val context = applicationContext
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
As you know in Android, the roots of the garbage collector are: static variables and active threads.
Case 1. We put applicationContext in the...