Hi,
I've made a very simple app. User set two edittext (Running time and walk time) and then press start.
Start initialize a service that notify user after running time and then after walk time and then after running time and so on.
It works for some time and then stop running. after a long time the service back running again.
Any thoughts?
tks,
Riani
I've made a very simple app. User set two edittext (Running time and walk time) and then press start.
Start initialize a service that notify user after running time and then after walk time and then after running time and so on.
It works for some time and then stop running. after a long time the service back running again.
Any thoughts?
B4X:
'Main
Sub btnIniciar_Click
If edtTempoCaminhada.Text <> "" AND edtTempoCorrida.Text <> "" Then
tempoCaminhada = edtTempoCaminhada.Text
tempoCorrida = edtTempoCorrida.Text
StartService("Cronometro")
Else
Msgbox ("Entre com os tempos!","Erro")
End If
End Sub
'Service
Sub Service_Create
n.Initialize
n.Icon = "icon"
n.Vibrate = False
n.OnGoingEvent = True
n.SetInfo("Info", "Prevent from being killed", Main)
Service.StartForeground(1,n)
n2.Initialize
n2.Icon = "icon"
n2.Vibrate = False
n2.AutoCancel = True
End Sub
Sub Service_Start (StartingIntent As Intent)
' Dim volumeAtual As Int
If Main.programaEmExecucao = "Sim" Then
MediaPlayer1.Initialize( )
Select Main.etapa
Case "Corrida"
'....
n2.SetInfo("Info", "Correr", "")
n2.Notify(1)
MediaPlayer1.Load(File.DirRootExternal & "/ApoioCaminhadaCorrida/", "correr.mp3")
MediaPlayer1.Play
Main.etapa = "Caminhada"
StartServiceAt("Cronometro",DateTime.Now+Main.tempoCorrida*1000,True)
'StopService("Cronometro")
Case "Caminhada"
'....
n2.SetInfo("Info", "Caminhar", "")
n2.Notify(1)
MediaPlayer1.Load(File.DirRootExternal & "/ApoioCaminhadaCorrida/", "caminhada.mp3")
MediaPlayer1.Play
Main.etapa = "Corrida"
StartServiceAt("Cronometro",DateTime.Now+Main.tempoCaminhada*1000,True)
'StopService("Cronometro")
End Select
Else
Service.StopForeground(0)
StopService("Cronometro")
End If
End Sub
tks,
Riani