Android Question Notification

guido valentino

Member
Licensed User
Longtime User
Hi, is there a way to send a notification after a tot of time even if the application is closed? for example, to alert the user that something it is recharged:) thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
Yes using a service. You will initialize the notification from it. The point you will have to think about is the activity shown if the user clicks on the notification itself.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Upvote 0

guido valentino

Member
Licensed User
Longtime User
Yes i see, infact the notification works. But only when i close the app and this remains in background. If i kill the app notifications don t work
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
would you post your code ? Perhaps do You kill the app manully so you kill the service too ?
 
Upvote 0

guido valentino

Member
Licensed User
Longtime User
for example
- In Main
B4X:
Sub btnCreateNotifications_Click
    StartService(notifica)
   
End Sub
-In Notifica
B4X:
#Region  Service Attributes 
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Dim timer1 As Timer
End Sub
Sub Service_Create
timer1.Initialize("timer1",7000)
End Sub

Sub Service_Start (StartingIntent As Intent)
    timer1.Enabled=True
End Sub

Sub Service_Destroy

End Sub
Sub timer1_tick
        Dim n As Notification
        n.Initialize
        n.SetInfo("Notification " & 1, "abcde", Me)
        n.Icon = "icon"
        n.Notify(1)
        timer1.Enabled=False
End Sub
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
perhaps do You want to restart the service when you stop the app ? If yes, you could try to insert a
StartServiceAt in Service_Destroy ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top