Android Question Notification Service

SternFaun

Member
Licensed User
Hello together,

how can I create a service (always running in the background, starting by systemboot), which checks a date typed in my app and gives a notification (how can I create a notification)?

Thanks for your help.
 

SternFaun

Member
Licensed User
Hello, thanks for your answers. I finished my app, but I have a last problem:

The Activity (it is only one) puts a date in a Public process global ("ServiceDatum").

B4X:
Sub Process_Globals

   Private n As Notification
   Public ServiceDatum2 As Long
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)

StartServiceAt(Me, DateTime.Now + 10 * DateTime.TicksPerSecond, True)  

            ServiceDatum2 = Main.ServiceDatum
            If ServiceDatum2 <= DateTime.Now Then

            n.Initialize
            n.Icon = "icon"

            n.SetInfo("Notizen","Notiz zu erledigen",Main)
            n.AutoCancel = True
            n.Notify(1)
            n.Light = True

    Else
    End If

End Sub

I dont want the Service to start when I start the activity or when the activity is open. I tried only do "if IsPaused(Main)", but this didnt word.

Second problem is, that if I press the notification the activity does not open (as defined in "n.SetInfo("Notizen","Notiz zu erledigen",Main)"), it appears just a empty black screen with the title.

Any solutions?
 
Upvote 0

SternFaun

Member
Licensed User
Thanks for your answer.The app should work like a calendar. the app writes a date in a file. the service should check all 10 minutes if the date written in the file is the actual date (datetick in file <= dateutils.now). this means the service has to run all ten minutes (for example) also if the activity isnt started the whole time.
 
Upvote 0

SternFaun

Member
Licensed User
Ok. That is a good thing. but if i say start it every 12h, isnt it the same?

Do you have an idea why the app does not open when i click the notification? where is the entry point in the activiy after clicking the notification, does it always start in the activity create sub?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is hard to say without seeing the complete code. The code you posted assumes that the process will not be killed. This is a wrong assumption. You should save any important information in a file.

where is the entry point in the activiy after clicking the notification, does it always start in the activity create sub?
If the activity was destroyed then Activity_Create will be called. Activity_Resume is always called.
 
Upvote 0
Top