Android Question Launcher icon and notifications

luke2012

Well-Known Member
Licensed User
Longtime User
Hello everybody,
I have implemented a module whose purpose is to display a notification when new content has been posted on the backend of the app.

To ensure the correct functioning of the module, even in the latest versions of Android, I followed the tutorial by @Erel Background location tracking (https://www.b4x.com/android/forum/threads/background-location-tracking.99873/).

So far so good. The module works well, every 1800 seconds it starts and checks if new contents have been inserted. If there are new contents send a notification to the user:

B4X:
Sub Service_Start (StartingIntent As Intent)    

    Service.StartForeground(nid, CreateNotification("MYAPP", "icon"))        

    Private NumOfSeconds As Int = 1800
    StartServiceAt(Me, DateTime.Now + NumOfSeconds * DateTime.TicksPerSecond, True)

      If ArtsNIDs.Size > 0 Then
        Private prevArtCounter As Int = KVSCounts.Get(FIELD_ARTS_COUNTER)
        If ArtsNIDs.Size > prevArtCounter Then
         
            Dim n As Notification = CreateNotification("There is some news for you! Find out which ones...", "smiley")
            n.Notify(nid)
         
        Else
            Log("ARTICLES - NO NEWS!")
        End If
        KVSCounts.Put(FIELD_ARTS_COUNTER, ArtsNIDs.Size) '--->     'Update article counter
    End If
End Sub

The problem is that now (as you can see from the attached screenshoot), the symbol "1" remains perpetually and my users (including my client) are clamoring for me to remove / disable the permanent notification symbol as it creates confusion ( because there is actually no new content to read) and it's annoying (for them). Even my client has repeatedly told me to remove this permanent notification with the utmost urgency (just to say how important it is).

Before making changes to the code (since it is an app already in production, used and published on the Play Store), I wanted to understand if, in your opinion, it is a solvable problem (i.e. NOT showing the permanent notification icon) or not .

Thanks in advance for your suggestions / help.

Luca.

Schermata 2022-03-28 alle 08.43.04.png
 

Attachments

  • 1648450129929.png
    1648450129929.png
    326 bytes · Views: 22
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
A Foregroundservice Icon can not be removed. Stop the foregroundservice to be able to remove it.

Hi @DonManfred. First of all thanks for your reply.

If I stop the service the notifications will no longer work and the purpose of this service is to notify (about a specific event).

What I would like to implement is a service that starts every x seconds and displays a notification if a specific event occurs (if ...).
But once the notification is opened by the user after that it should go away.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If you want to run a service every x seconds (where seconds is <1800) then you HAVE to use a Foreground-Service. This Service MUST HAVE an Icon and can not be removed.

If the seconds are 1800+ Seconds then you can use StartServiceAtExact, let the service start, give a notification if one is needed and then stop the service after you rescheduled it. No additional Notification is needed in this case.
 
Upvote 0
Top