Android Question Returning to the sub after the timer ?

Devv

Active Member
Licensed User
Longtime User
i have a code like this

B4X:
Sub Process_Globals

    Dim soso As AudioRecorder
    Dim Timer1 As Timer
End Sub


Sub Service_Start (StartingIntent As Intent)
soso.Initialize()
Timer1.Initialize("Timer1",6000)

soso.AudioSource = soso.AS_MIC
    soso.OutputFormat = soso.OF_THREE_GPP
    soso.AudioEncoder = soso.AE_AMR_NB
    soso.setOutputFile(File.DirRootExternal,"test.mp3")
    soso.prepare
    ToastMessageShow("AudioRecorder is ready to record.",False)
    soso.start
    ToastMessageShow("started",True)
    Timer1.Enabled = True
   ' i want to come back here after the timer finish counting
End Sub



Sub Timer1_Tick
    Timer1.Enabled = False
    'Call your stop recording method
    ToastMessageShow("Recording stopped.",False)
    soso.Stop
    connection.
'how can i return from here to Sub Service_Start ?
End Sub
 

stevel05

Expert
Licensed User
Longtime User
It's not possible, the Timer will run it's tick sub as soon as it can after the defined time interval has elapsed and is not related directly to the program flow. Enabling the timer will not call the Tick routine instantly, it will wait for the defined time interval to pass.

If you want to do something after the Timer_Tick routine has run, you will need to call a Sub at the end of the Tick routine.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User

is it OK if i wrote the rest of my program in theTimer1_Tick sub ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Theoretically yes, but what happens if the timer gets started again?

What do you want to do after the recording has stopped?

It feels to me like it would be better to call another sub using CallSubDelayed so that the Timer_Tick sub can return, then the program will continue from the called sub.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…