Karn / notify

Simplified notification construction and delivery for Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notify.cancelNotification(id) causes KotlinNullPointerException

NLLAPPS opened this issue · comments

Hi,

Notify.cancelNotification(id) Seems to cause KotlinNullPointerException if you have not used/initialized Notify before. This is probably "notificationManager" is null in Notify.kt at cancelNotification(id: Int)

Deprecated Notify.with(context).cancel(id) works fine.

Where is the scenario I am able to reproduce it. I have following function where it can be called with "false" before "true". Crash happens when it is called with "false" before it "true". Crash does not happen if you call it with "true" first.

 `fun focusModeIsOn2(context: Context, show: Boolean) {
    if (show) {
        Notify.with(context)
               { ...... }.show(focusModeOnNotificationId)
    } else {
        //Notify.with(context).cancel(focusModeOnNotificationId)
        Notify.cancelNotification(focusModeOnNotificationId)
    }


      }`

Awesome find @NLLAPPS! I've created a PR above to address the issue.

Cheers!