Would I have any problem/drawback calling an activity on an companion object like that? Memory Leak or something like that?
Copy code
companion object {
fun start(context: Context) {
launch{
if (context.prefs.fooProperty) //ext fun on shared pref{
val intent = Intent(context, Foo::class.java)
context.startActivity(intent)
}
}
}
}
r
rkeazor
07/23/2018, 3:44 PM
Why would you start a activity inside a coroutine? The issue would be ,that you might not have the current context
l
leosan
07/23/2018, 4:09 PM
I was just curious about the downsides, I don’t even like this approach of starting activities. I think is on a coroutine because of the diskwrites of the shared preferences
r
rkeazor
07/23/2018, 4:10 PM
Yea shared Preference needs to be handled in a separate thread or suspended function. But not with the changing of activity
rkeazor
07/23/2018, 4:12 PM
you can have it ,so that it changes activity, after the function has completed
👍 1
u
ursus
07/23/2018, 8:48 PM
yes it will leak, i.e. it will hold a context reference until the method and the lambda is finished, so if its async, and that context is activity, it might go through destroying
👌 1
ursus
07/23/2018, 8:49 PM
and that lambda will hold onto that reference until finished