https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

suhas

09/12/2021, 2:17 AM
What the idiomatic way of doing this in Kotlin?
Copy code
if (mNotificationManager == null) {
                mNotificationManager = this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
 }
e

ephemient

09/12/2021, 2:23 AM
Copy code
val notificationManager by lazy {
    context.getSystemService<NotificationManager>()
}
androidx.core.content.getSystemService avoids a cast, kotlin.lazy handles init-once
👍 1
2 Views