Android Question [SOLVED] - Widget creates additional notification

rleiman

Well-Known Member
Licensed User
Greetings,

I noticed if I place a widget on the phone's home screen an additional notification is created. Can I prevent the app from creating the additional notification?

The attached screen shot will show the added notification created. I have only one area in the app that creates a notification and it's in a service module. The added notification seems to have a default title and body. The text in those areas are the same is the app name repeated throughout the notification.

If I don't place the widget on the home screen, then only 1 notification is displayed all the time which is what I wanted.

This is the only coding in the app that creates a notification. It's called only one time.

B4X:
Sub Service_Start (StartingIntent As Intent)

    Service.StartForeground(nid, CreateNotification( _
        "Now running in the background.", _
        "Tapping this notification will open the app.", _
        Main ))
   
    StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)

    Log("At Service_Start")
   
    StartGps
    StartTimer
    blnServiceStarted = True
End Sub
B4X:
Sub CreateNotification (strTitle As String, strBody As String, objActivity As Object) As Notification

    Dim notification As Notification

    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "icon"
    notification.SetInfo(strTitle, strBody, objActivity)

    Return notification
End Sub
Thanks.

WhatsApp Image 2020-02-20 at 22.35.04.jpeg
 
Last edited:

rleiman

Well-Known Member
Licensed User
Hi Erel,

Thanks. I worked as soon as I added Service.StopAutomaticForground in the widget service module.

B4X:
Sub Service_Start (StartingIntent As Intent)

    UpdateTheWidget
   
    Service.StopAutomaticForeground
   
    If rv.HandleWidgetEvents(StartingIntent) Then  
        Return
    End If
End Sub
 
Top