Android Question B4X stop application execution

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
Within a B4X app (in my case B4XPages app) I need to stop (and inform the user) that the app can't download the data (tipically when te ws service isn't available or in other case where I can't have a json to parse and use to show data).

Is my code correct for a B4X app ? I mean, which is the correct way to stop the app execution and show a msgbox to the user in a compatible way for B4X apps?

B4X:
'B4XMainPage / B4XPage_created
    If NoData = true  Then
        Private nSecs As Int = 10
        xui.MsgboxAsync("I can't download the app contents in this moment", Application.LabelName)
        Sleep (nSecs * 1000)
        ExitApplication
    End If
 

luke2012

Well-Known Member
Licensed User
Longtime User
You are not expected to kill the process with ExitApplication. The OS can treat it as a crash.
In iOS you can't end the app at all.
In Android you can show the home screen though it will probably better to show a message and let the user retry.

"In Android you can show the home screen": you mean something like this ?

B4X:
'B4XMainPage / B4XPage_created
    If NoData = true  Then
          B4XPages.ShowPage ("home")
    End If
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User

Thank you @Erel. But this is valid only within B4A App. I'm developing a [B4X] [B4XPages] App.
My code (within B4XPages / B4XMainPage) is:

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Wait For (ShowSplashScreen) Complete (Unused As Boolean)
    Root.LoadLayout("home")
    B4XPages.SetTitle(Me, "Home - " & Application.LabelName)
    toast.Initialize(Root)

   'AppGlobals is a class when I put all shared subs and consts
    B4XLoadingIndicator1.Show
    Wait For (AppGlobals.GetSubCatsNIDs (AppGlobals.SUBCATS1_TEST_ID, AppGlobals.user, AppGlobals.psw)) Complete (SubCatsNIDs1 As List)

    If SubCatsNIDs1.Size = 0  Then ---> no data from server
    '--> Here I should alert the user (ex. a toast message) and stop the execution of the remaining code
    End If

'Remaining code
   Wait For (AppGlobals.GetSubCatsNIDs (AppGlobals.SUBCATS2_TEST_ID....
   Wait For (AppGlobals.GetSubCatsNIDs (AppGlobals.SUBCATS3_TEST_ID....

    B4XLoadingIndicator1.hide
End sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…