I create the simple meditation bell app that ring the bell every interval, between 20 seconds to 10 minutes according to setting by service module.
But the service module keep stopping to ring the bell after run for some time. The bell will stop sooner with 20 seconds interval. But the ongoing notification still showing.
I think that it stop because of stack overflow ?
I don't know how to solve it.
It would be so kind to help me out. :sign0104:
Zip of the project is in attached.
But the service module keep stopping to ring the bell after run for some time. The bell will stop sooner with 20 seconds interval. But the ongoing notification still showing.
I think that it stop because of stack overflow ?
I don't know how to solve it.
It would be so kind to help me out. :sign0104:
Zip of the project is in attached.
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim DulationV As Int
Dim TextV As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim btnStart As Button
Dim btnStop As Button
Dim Label1 As Label
Dim SeekBar1 As SeekBar
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Note10")
If FirstTime Then
TextV = "2 Minutes"
DulationV = 120
End If
End Sub
Sub Activity_Resume
If IsPaused(MService)=True Then
btnStart.Enabled = True
btnStop.Enabled = False
Else
btnStart.Enabled = False
btnStop.Enabled = True
End If
SeekBar1.Value = DulationV/10
Label1.Text = TextV
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnStop_Click
CancelScheduledService(MService)
StopService(MService)
btnStart.Enabled = True
btnStop.Enabled = False
End Sub
Sub btnStart_Click
StartService(MService)
Activity.Finish
End Sub
Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
Dim MinuteV As Int
Dim SecondV As Int
If Value < 2 Then
Value = 2
SeekBar1.Value = 2
End If
SecondV = Value*10 Mod 60
MinuteV = (Value*10 - SecondV)/60
TextV = ""
If MinuteV > 0 Then
TextV = MinuteV & " Minutes "
End If
If SecondV >0 Then
TextV = TextV & SecondV & " Second"
End If
Label1.Text = TextV
DulationV = Value*10
End Sub
B4X:
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim N As Notification
Dim MP As MediaPlayer
Dim DT As Int
End Sub
Sub Service_Create
n.Initialize
n.Icon = "icon"
n.Sound = False
n.Vibrate= False
n.Light=False
n.OnGoingEvent=True
n.SetInfo("Mindfulness Bell", "Bell will ring every " & Main.TextV , Main)
n.Notify(1)
MP.Initialize()
MP.Load(File.DirAssets,"bell10s.ogg")
DT = Main.DulationV
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("",DateTime.Now+DT*DateTime.TicksPerSecond,True)
If MP.IsPlaying = True Then
MP.Stop
MP.Load(File.DirAssets,"s3.mp3")
End If
MP.Play
End Sub
Sub Service_Destroy
n.Cancel(1)
End Sub
Attachments
Last edited: