Would I have any problem/drawback calling an activ...
# android
l
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
Why would you start a activity inside a coroutine? The issue would be ,that you might not have the current context
l
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
Yea shared Preference needs to be handled in a separate thread or suspended function. But not with the changing of activity
you can have it ,so that it changes activity, after the function has completed
👍 1
u
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
and that lambda will hold onto that reference until finished