B4J Question [ Steam Client ] Closes the Form, but doesn't kill the application .

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
I'm making a game for steam ( steampowered.com ) it works fine, but when I try to "kill" the game via SteamClient by clicking on "Stop Run",
1626360180207.png

the Form closes, but the application keeps running and it's only killed when I I go to the B4J client and click on "Kill Process", is there any way I can handle the request to close the game by the steam client?

1626360244480.png
 

LucaMs

Expert
Licensed User
Longtime User
In your B4XMainPage there is:
B4X:
Private Sub Button1_Click
    B4XPages.ShowPageAndRemovePreviousPages("teste")
End Sub
This way you CLOSE the B4XMainPage (remove it from the B4XPages stack).

In your "teste" B4XPage you have:
B4X:
    If Result = xui.DialogResponse_Positive Then
        'CASE POSITIVE-  RETURN TO MAINPAGE
        Return True
"RETURN TO MAINPAGE" - WRONG! You closed/removed the "main page" !!!
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
B4X:
B4XPages.ShowPageAndRemovePreviousPages("teste")
to open "teste", closing the "current" page on top, which is B4XMainPage.
So that log will be written when B4XMainPage disappers (closes).
Did you write "test_disappear" because you think the B4XPage "teste" is "disappearin" or because you think the app is closing, there?

initially I was looking for some event that was previously executed from CloseRequest, so that I could filter if it was the user who requested the application to close, or if it was Steam ...

so in this case I created the b4xPages events to test if any would give me some basis to filter whether I should wait for the user or if it closes directly with the steam request
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Since I downloaded the latest version of the project you attached, I no longer have that library (and if I did I don't know if I could use it, if you need a username and password, for example, or something else).

Anyway, what should be the "path", the "flow" of your app?

1 - B4XMainPage opens "teste"
2 - In "teste" ask the user if he wants to close "teste" or does he want to close the app directly from inside "teste"?

Do you want it to work like this?
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
B4X:
    Dim sf As Object = xui.Msgbox2Async("Close?", "Title", "Yes", "Cancel", "No", Null)
Means it "Close the game-teste" or "close the app"?

close only the "game-test" page and go back to the previous page, if the user presses: Positive, else close the application if the pages are closed by steam
 

Attachments

  • steam_appid.txt
    3 bytes · Views: 213
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
Since I downloaded the latest version of the project you attached, I no longer have that library (and if I did I don't know if I could use it, if you need a username and password, for example, or something else).

Anyway, what should be the "path", the "flow" of your app?

1 - B4XMainPage opens "teste"
2 - In "teste" ask the user if he wants to close "teste" or does he want to close the app directly from inside "teste"?

Do you want it to work like this?

the flow would be as follows: The user opens the game, and the ticket opens the Lobby, if he clicks on play, he is sent to the Game page, if he clicks on the window's close button, a MsgBox opens asking if he is right about the decision to leave.
But by chance, he can close the game using Steam (since I intend to sell my game there), if he chooses to close by steam, all pages are closed, but the game keeps running in that Wait For
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4XMainPage:
Private Sub Button1_Click

    B4XPages.ShowPageAndRemovePreviousPages("teste")

End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
    
    Log("B4XMainPage close request")
    
    ExitApplication
    Return True
End Sub


teste page:
Private Sub B4XPage_CloseRequest As ResumableSub
   
    Log("CloseRequest Test")
   

    Dim sf As Object = xui.Msgbox2Async("Close?", "Title", "Yes", "Cancel", "No", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    Log("after WAIT FOR")
    If Result = xui.DialogResponse_Positive Then
        B4XPages.ShowPage("mainpage")
        Return True
    Else
        Return False
    End If
   
End Sub
 
Last edited:
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
B4XMainPage:
Private Sub Button1_Click

    B4XPages.ShowPageAndRemovePreviousPages("teste")

End Sub

teste page:
Private Sub B4XPage_CloseRequest As ResumableSub
   
    Log("CloseRequest Test")
   

    Dim sf As Object = xui.Msgbox2Async("Close?", "Title", "Yes", "Cancel", "No", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    Log("after WAIT FOR")
    If Result = xui.DialogResponse_Positive Then
        B4XPages.ShowPage("mainpage")
        Return True
    Else
        Return False
    End If
   
End Sub

I recorded a video to demonstrate it better: VIDEO
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I have had a similar problem of incomplete waitfors after App was killed. It was solved by not having a wait for. Make your own msgbox, it is simple enough.

https://www.b4x.com/android/forum/threads/msgbox-and-msgbox2-modal.44945/post-275239

One panel containing a Label "Are you sure", and Yes No buttons.
1. define a global Private ClosingConfirmed as Boolean
2. In B4XPage_CloseRequest
test ClosingConfirmed if yes return True
make the msg panel visible and return False.

On the button events, if Yes then to set ClosingConfirmed = True and call B4XPages.ClosePage again
if No, just return
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
I have had a similar problem of incomplete waitfors after App was killed. It was solved by not having a wait for. Make your own msgbox, it is simple enough.

https://www.b4x.com/android/forum/threads/msgbox-and-msgbox2-modal.44945/post-275239

One panel containing a Label "Are you sure", and Yes No buttons.
1. define a global Private ClosingConfirmed as Boolean
2. In B4XPage_CloseRequest
test ClosingConfirmed if yes return True
make the msg panel visible and return False.

On the button events, if Yes then to set ClosingConfirmed = True and call B4XPages.ClosePage again
if No, just return
would you have an example? still seems confused to me, i think i need to rest my mind a little xD
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub B4XPage_CloseRequest As ResumableSub
    'Globals
    'Private confirm As B4XView
    'Private confirmExit As Boolean

    If confirmExit Then Return True
    confirm = xui.CreatePanel("")
    confirm.SetLayoutAnimated(0, 0, 0, 350, 25)
    Dim msgLbl As Label: msgLbl.Initialize("")
    msgLbl.Text = "Are you sure you want to quit?"
    Dim yesBtn As Button: yesBtn.Initialize("confirmed")
    yesBtn.Text = "Yes"
    Dim noBtn As Button: noBtn.Initialize("cancelled")
    noBtn.Text = "Cancel"
    confirm.AddView(msgLbl, 5, 0, 170, 25)
    confirm.AddView(yesBtn, 180, 0, 50, 25)
    confirm.AddView(noBtn, 240, 0, 80, 25)
    Root.AddView(confirm, Root.Width/2 - confirm.Width/2, Root.Height/2 - confirm.Height/2, confirm.Width, confirm.Height)
    Return False
End Sub

Private Sub confirmed_Click
    confirmExit = True
    B4XPages.ClosePage(Me)
End Sub

Private Sub cancelled_Click
    confirmExit = False
    confirm.Visible = False
End Sub
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
it didn't work... :c
there would have to be some form of confirmation if it was requested externally, or if something was closed before entering the CloseRequest sub...
I made an example here to test, if you can take a look, I would appreciate it!
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I would guess that the Steam client doesn't generate a CloseRequest event. You would need to check that with Steam.
If it doesn't you can't intercept external closing process.

Did my code prevent the dangling "WaitFor"?
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
I would guess that the Steam client doesn't generate a CloseRequest event. You would need to check that with Steam.
If it doesn't you can't intercept external closing process.
On this VIDEO shows in a practical way how the B4J application reacts when it is closed by Steam

Did my code prevent the dangling "WaitFor"?
Yes !! Thanks :D
 
Upvote 0
Top