Stack over flow?

jeeradate

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

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

  • medibell.zip
    90.9 KB · Views: 222
  • medibell.apk
    184.3 KB · Views: 207
Last edited:

jeeradate

Member
Licensed User
Longtime User
I order to prevent the service module from stop working, I move all the tasks to main activity as below code but problem didn't solve. I keep stop working.

Does anyone know the reasons?

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
    Dim N As Notification
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
        n.Initialize
        n.Icon = "icon"
        n.Sound = False
        n.Vibrate= False
        n.Light=False
        n.OnGoingEvent=True
    End If
End Sub

Sub Activity_Resume
    If IsPaused(MService)=True Then
        btnStart.Enabled = True
        btnStop.Enabled = False
        n.Cancel(1)
    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
    n.Cancel(1)
End Sub
Sub btnStart_Click
    StartService(MService)
    Activity.Finish

    n.SetInfo("Mindfulness Bell", "Bell will ring every " & TextV , "")
    n.Notify(1)
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 MP As MediaPlayer
    Dim DT As Int

End Sub
Sub Service_Create
    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,"bell0s.ogg")
    End If
    MP.Play
End Sub

Sub Service_Destroy
    Main.N.Cancel(1)
End Sub
 

Attachments

  • medibell.zip
    91 KB · Views: 206
Upvote 0

jeeradate

Member
Licensed User
Longtime User
I test my application in Samsung Galaxy Note 10.1 Android Version 4.1.1, so far it still not reliable. I test my SSGN 10.1 with "Mindfulness bell" (Java base) it run for few days without any stop in operation.
 
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I have given Erel's MediaPlayer to Jeeradate K. already,I think him be happy.
 
Upvote 0

jeeradate

Member
Licensed User
Longtime User
Can you post the error message from the logs?

Thank you for your kind response.

Below is the some of the error log before it stop. It can run up to 30 minute before error.

B4X:
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Start **
** Service (mservice) Create **
** Service (mservice) Start **
** Service (mservice) Start **
mservice_service_start (B4A line: 20)
MP.Load(File.DirAssets,"bell0s.ogg")
java.io.FileNotFoundException: bell0s.ogg
    at android.content.res.AssetManager.openAssetFd(Native Method)
    at android.content.res.AssetManager.openFd(AssetManager.java:331)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:62)
    at noklek.com.medibell2.mservice._service_start(mservice.java:154)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
    at noklek.com.medibell2.mservice.handleStart(mservice.java:61)
    at noklek.com.medibell2.mservice.onStartCommand(mservice.java:46)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2554)
    at android.app.ActivityThread.access$2000(ActivityThread.java:140)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1334)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Unable to start service noklek.com.medibell2.mservice@41739c40 with Intent { flg=0x4 cmp=noklek.com.medibell2/.mservice (has extras) }: java.lang.RuntimeException: java.io.FileNotFoundException: bell0s.ogg
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2571)
    at android.app.ActivityThread.access$2000(ActivityThread.java:140)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1334)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: bell0s.ogg
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
    at noklek.com.medibell2.mservice.handleStart(mservice.java:61)
    at noklek.com.medibell2.mservice.onStartCommand(mservice.java:46)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2554)
    ... 10 more
Caused by: java.io.FileNotFoundException: bell0s.ogg
    at android.content.res.AssetManager.openAssetFd(Native Method)
    at android.content.res.AssetManager.openFd(AssetManager.java:331)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:62)
    at noklek.com.medibell2.mservice._service_start(mservice.java:154)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
    ... 14 more
** Service (mservice) Create **
** Service (mservice) Start **
** Service (mservice) Start **
mservice_service_start (B4A line: 20)
MP.Load(File.DirAssets,"bell0s.ogg")
java.io.FileNotFoundException: bell0s.ogg
    at android.content.res.AssetManager.openAssetFd(Native Method)
    at android.content.res.AssetManager.openFd(AssetManager.java:331)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:62)
    at noklek.com.medibell2.mservice._service_start(mservice.java:154)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
    at noklek.com.medibell2.mservice.handleStart(mservice.java:61)
    at noklek.com.medibell2.mservice.onStartCommand(mservice.java:46)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2554)
    at android.app.ActivityThread.access$2000(ActivityThread.java:140)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1334)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Unable to start service noklek.com.medibell2.mservice@4173ac40 with Intent { flg=0x4 cmp=noklek.com.medibell2/.mservice (has extras) }: java.lang.RuntimeException: java.io.FileNotFoundException: bell0s.ogg
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2571)
    at android.app.ActivityThread.access$2000(ActivityThread.java:140)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1334)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: bell0s.ogg
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
    at noklek.com.medibell2.mservice.handleStart(mservice.java:61)
    at noklek.com.medibell2.mservice.onStartCommand(mservice.java:46)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2554)
    ... 10 more
Caused by: java.io.FileNotFoundException: bell0s.ogg
    at android.content.res.AssetManager.openAssetFd(Native Method)
    at android.content.res.AssetManager.openFd(AssetManager.java:331)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:62)
    at noklek.com.medibell2.mservice._service_start(mservice.java:154)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
    ... 14 more
 
Last edited:
Upvote 0

jeeradate

Member
Licensed User
Longtime User
The file bell0s.ogg is missing from the Files tab.

Unlike the file bell10.ogg which probably exists.

Thank you very much.
I think you got the point.

And you may be right, I found this code is error.
But that part of code should not be executed as the bell10s.ogg is 10 seconds long but the minimum interval is 20 seconds. The mediaplayer (MP) should finished it jobs.

I run it again and will let you know.
Thank you again for teaching me how to use the log.

:wav:

B4X:
Sub Service_Start (StartingIntent As Intent)
    StartServiceAt("",DateTime.Now+DT*DateTime.TicksPerSecond,True)
    If MP.IsPlaying = True Then
        MP.Stop
        MP.Load(File.DirAssets,"bell0s.ogg")
    End If
    MP.Play
End Sub
Then I correct it into this

B4X:
Sub Service_Start (StartingIntent As Intent)
    StartServiceAt("",DateTime.Now+DT*DateTime.TicksPerSecond,True)
    If MP.IsPlaying = True Then
        MP.Stop
        MP.Load(File.DirAssets,"bell10s.ogg")
    End If
    MP.Play
End Sub
 
Last edited:
Upvote 0

jeeradate

Member
Licensed User
Longtime User
I have given Erel's MediaPlayer to Jeeradate K. already,I think him be happy.

Thank you very much Khun Theera,

All my knowledge about Android Programming is come from this forum and all from everybody helping me, especially Khun Erel.

(Khun in Thai language is Sir)
 
Upvote 0

jeeradate

Member
Licensed User
Longtime User
The file bell0s.ogg is missing from the Files tab.

Unlike the file bell10.ogg which probably exists.

Thank you very much, after correct the file name the program can run non stop through the night.

:sign0142:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…