hi all.
i need to make a simple check on my website to see if exist a new user mensage and show a notification if exist = true.
i m trying to make this with PostString, this works fine when the app is opned, but when i close the app, i press exit on my main activity the service stop, with Service.StartForeground, my service stop too.
why this? what the best way to make a simple notification with a timer
2 - 2 hours go to my website and check if userid have new mensage, if have show notification.
can someone help me pls? i m many time working on this and not sucess =(
its possible to use keyvaluestore + httppost in a service to check my website every 2 hours? the services allow keyvalustore and http?
i need to make a simple check on my website to see if exist a new user mensage and show a notification if exist = true.
i m trying to make this with PostString, this works fine when the app is opned, but when i close the app, i press exit on my main activity the service stop, with Service.StartForeground, my service stop too.
why this? what the best way to make a simple notification with a timer
2 - 2 hours go to my website and check if userid have new mensage, if have show notification.
can someone help me pls? i m many time working on this and not sucess =(
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
Dim Notification1 As Notification
Dim tempo As Timer
Dim contador As Int
Dim target, fp As String
Dim kv As KeyValueStore
Dim userid As Int
End Sub
Sub Service_Create
If File.ExternalWritable Then target = File.DirDefaultExternal Else target = File.DirInternal
File.MakeDir(target, "lala")
fp = File.Combine(target,"lala")
kvs.Initialize(fp, "data")
tempo.Initialize("Timer", 1000)
Notification1.Initialize
Notification1.Icon = "icon"
Notification1.Light = True
Notification1.Sound = True
Notification1.Vibrate = True
Notification1.SetInfo("lalala", "lalala", Main)
userid = kvs.GetObject("UserID")
tempo.Enabled = True
Service.StartForeground(1, Notification1)
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
Sub Timer_Tick
contador = contador + 1
If contador = 10 Then
recebemensagens
contador = 0
End If
End Sub
Sub recebemensagens
Dim recebemensagem As HttpJob
recebemensagem.Initialize("resultadorecebemensagem", Me)
recebemensagem.PostString("http://lalal.com/user/", "data=UserID:"&userid)
End Sub
Sub JobDone (job As HttpJob)
If job.Success Then
Select job.JobName
Case "resultadorecebemensagem"
Notification1.SetInfo("lala", "Nome mensagem", Main)
Notification1.Notify(1)
End Select
Else
Notification1.SetInfo("lala", "Nome mensagem", Main)
Notification1.Notify(1)
ProgressDialogHide
ExitApplication
End If
job.Release
End Sub
its possible to use keyvaluestore + httppost in a service to check my website every 2 hours? the services allow keyvalustore and http?