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. :p
 
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:
[GICON] ### GPS_ENABLED_CHANGE_ACTION ### (false)
reportStatus status: 4
sendEvent(1,0,700120834,false) back
Recipient 21267
Buffer count: 4
WIN DEATH: Window{e941df9 u0 fg.cronomillemiglia_ultra/fg.cronomillemiglia_ultra.main}
Process fg.cronomillemiglia_ultra (pid 21267) has died
cleanUpApplicationRecord -- 21267
Scheduling restart of crashed service fg.cronomillemiglia_ultra/.smcrono in 1000ms
Scheduling restart of crashed service fg.cronomillemiglia_ultra/.starter in 1000ms
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
Looper::removeFd(52) is failed, result(0), input channel 'ClientState{a40316d uid 10210 pid 21267} (client)'
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
HtcSystemUPolicy [canLog (default)] category: launch, enable: true

Logs with Stop-Service:
[GICON] ### GPS_ENABLED_CHANGE_ACTION ### (false)
reportStatus status: 4
sendEvent(1,0,700324198,false) back
Recipient 22082
failed to post message as target looper for handler 0 is gone.
Buffer count: 4
WIN DEATH: Window{8780823 u0 fg.cronomillemiglia_ultra/fg.cronomillemiglia_ultra.main}
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
Process fg.cronomillemiglia_ultra (pid 22082) has died
cleanUpApplicationRecord -- 22082
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
Looper::removeFd(52) is failed, result(0), input channel 'ClientState{5489e8b uid 10210 pid 22082} (client)'
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
failed to post message as target looper for handler 0 is gone.
 
Upvote 0

Emme Developer

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

Logs with Stop-Service:
You can use also stopService(name), don't need callsub
 
Upvote 0
Top