Android Question Notification

guido valentino

Member
Licensed 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
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.
 

lemonisdead

Well-Known Member
Licensed User

guido valentino

Member
Licensed 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
 

lemonisdead

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

guido valentino

Member
Licensed 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
 

lemonisdead

Well-Known Member
Licensed 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 ?
 
Top