Android Question Cancelling ProgressDialogShow2

Sepehr-b

New Member
Hi,
How can I handle pressing back when the ProgressDialogShow2("Some text",True) is shown?
in the example below, I want to change it to :
ProgressDialogShow2("Downloading...", true)

and find a way to cancel the http job process if the user presses cancel or back key.

Any more help or sample about ProgressDialogShow2 is appreciated

B4X:
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://api.coindesk.com/v1/bpi/currentprice.json")
    ProgressDialogShow2("Downloading...", False)
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log("Error: " & j.ErrorMessage)
    End If
    ProgressDialogHide
    j.Release
 
Solution
You need to handle the back key in the _KeyPress Event

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
...
End Sub

there you check the KeyCode and return true to not close the activity and also put the dialog hide command something like this

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
     Select Case KeyCode
        Case 4 'BACK KEY
        ProgressDialogHide
    End Select
    Return True
End Sub

this will close the dialog once the user presses the back key button. if you want that button also to do other stuff you need to use some boolean's to do that like before you start the httpjob set a boolean to true like: httpjobprocess = true and check the value in the keypress event

B4X:
Sub Activity_KeyPress (KeyCode...

ilan

Expert
Licensed User
Longtime User
cancel the http job process
i dont think it is possible to cancel the http job process once u performed it.
sometimes there is no response and if you use ProgressDialogShow2(...,false) it can happen that it stays in that status forever. you can limit it with a timer so if after x sec no response from httpjob then hide the dialog with ProgressDialogHide so the user can continue with the app.
 
Upvote 0

Sepehr-b

New Member
i dont think it is possible to cancel the http job process once u performed it.
sometimes there is no response and if you use ProgressDialogShow2(...,false) it can happen that it stays in that status forever. you can limit it with a timer so if after x sec no response from httpjob then hide the dialog with ProgressDialogHide so the user can continue with the app.
Thanks ilan for the reply and the hint for cancelling http job...


my first question is how to get if the user has pressed back while ProgressDialogShow2('...' ,True) is displaying ?
suppose that the program is doing some controllable (i.e. inserting huge number of records into a table) task and i want to cancel it if the user press back.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
You need to handle the back key in the _KeyPress Event

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
...
End Sub

there you check the KeyCode and return true to not close the activity and also put the dialog hide command something like this

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
     Select Case KeyCode
        Case 4 'BACK KEY
        ProgressDialogHide
    End Select
    Return True
End Sub

this will close the dialog once the user presses the back key button. if you want that button also to do other stuff you need to use some boolean's to do that like before you start the httpjob set a boolean to true like: httpjobprocess = true and check the value in the keypress event

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
     Select Case KeyCode
        Case 4 'BACK KEY
                if httpjobprocess then ProgressDialogHide else Activity.Finish
    End Select
    Return True
End Sub
 
Upvote 0
Solution
Top