Android Question Stopping a paused activity from a service

ac9ts

Active Member
Licensed User
I have a streaming app that has the option of a sleep timer. I have the code working within the service to stop the stream and do any clean up. I would also like to stop the activity that called it.

This works when the activity is displayed/active.
B4X:
CallSubDelayed2(GUI, "Activity_Pause", True)
I'm not sure of what to do when the activity is paused. Is there a best practice for this kind of situation?
 

DonManfred

Expert
Licensed User
Calling Activity_pause manually Quits the Activity? And also destroy it? I doubt that...
Android will destroy the activity if needed.
 
Upvote 0

ac9ts

Active Member
Licensed User
This is my Activity_Pause code:
B4X:
    If UserClosed Then
        If Player.CurrentPosition > 0 Then                                            ' Store the re-start location
            SQL.SetPref("ReStartLoc", Player.CurrentPosition)
            SQL.SetPref("ReStartID", Player.NowPlaying)
        Else
            SQL.SetPref("ReStartLoc", "0")
            SQL.SetPref("ReStartID", "0")
        End If

        StopService(Player)
        StopService(DownloadService)
        StopService(HttpUtils2Service)
   
        SQL.CloseDB
       
        Common.StoreLastPlayed
       
        ' Close all activities
       
        Dim jo As JavaObject
        jo.InitializeContext
        jo.RunMethod("finishAffinity", Null)

    End If

It does shut everything down, the best I can tell.

The question remains, how can a service "wake up" a paused activity.
 
Upvote 0

DonManfred

Expert
Licensed User
how can a service "wake up" a paused activity.
B4X:
Callsubdelayed(...)
will open the activity. You can call a sub in the activity which itself then just use a Activity.Finish (and the Activity,Finish will raise the Activity_Pause after the sub finishes...).


Activity:
B4X:
Sub QuitActivity
    Activity.Finish
End Sub

Service:
B4X:
    CallSubDelayed(Main,"QuitActivity") ' Replace Main with the Activity you want to finish.

I expect this "more correct" than your Solution.
 
Upvote 0
Top