I'm trying to start a service, but I'm having prob...
# android
m
I'm trying to start a service, but I'm having problems during init
Copy code
class MyService : Service() {
    val myIntent = Intent(this, MyActivity::class.java)
    /* Other stuff */
}
This causes an NPE on
Context.getPackageName()
on the line where I'm making the Intent.
k
mrobinson: You could also do
val myIntent by lazy { Intent(this, MyActivity::class.java) }
. That way it won't be evaluated until the first time you access the val, which should be once the context is available
👍 2