Android Question Add a Pause in Sub Activity_Pause ?

D

Deleted member 103

Guest
Hi,
can one add a pause in sub "Activity_Pause" so that certain operations are executed before the function "ExitApplication"?

I ask because I want to be sure that certain services have been terminated.

Is this possible? Here's an example.
Or is there another possibility to wait until the service were to quit?

B4X:
Sub Activity_Pause (UserClosed As Boolean)

    If UserClosed Then
       
        'Service beenden
        CallSub(smCrono, "Service_Stop")
        CallSub(smAtomtime, "Service_Stop")
        CallSub(Starter, "Service_Stop")

        Sleep(200) 'I do not know whether this time is sufficient.

        ExitApplication
    End If
   
End Sub
 
D

Deleted member 103

Guest
OK, if you use "ExitApplication" then it is no longer necessary to stop the service manually, with "ExitApplication" the services are automatically terminated.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Have you tried using a timer to start ExitApplication after a time?
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
I think you can use a sub like this
In activity pause:
B4X:
CallSub2(YourService,"SubFinish",Me)
Wait for Finish_Service
CallSub2(YourService2,"SubFinish2",Me)
Wait for Finish_Service2

In service
B4X:
Sub Process_Globals
    CallBack as object
End Sub

Sub SubFinish(cb as object)
callback = cb
StopService(me)
End Sub

Sub Service_Destroy
CallSubDelayed(CallBack,"Finish_Service")
End Sub
 
Upvote 0
D

Deleted member 103

Guest
It will not work as the resumable sub will not be resumed until the activity is resumed.
That's right, I have already tried.

I tried it that way, and it seems to work.

In activity pause:
B4X:
Sub Activity_Pause (UserClosed As Boolean)

    If UserClosed Then
      
        'Service beenden
        CallSub(smCrono, "Service_Stop")
        CallSub(smAtomtime, "Service_Stop")
        CallSub(Starter, "Service_Stop")

        ExitApplication
    End If
  
End Sub

In service:
B4X:
Public Sub Service_Stop
    StopService(Me)
End Sub

Logs without Stop-Service:

Logs with Stop-Service:
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
You can use also stopService(name), don't need callsub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…