Android Question Delay back button function?

0CrimsonScythe0

Member
Licensed User
I want to display an ad when the user presses the back button for which I am using the following code:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean

    If KeyCode = KeyCodes.KEYCODE_BACK Then

ad2.loadAd()


    End If

End Sub
The problem is that the app closes before the ad can be displayed properly.
Is there a way to let the app exit only when the ad gets displayed and is cancelled?
 

RandomCoder

Well-Known Member
Licensed User
After loading your ad, start a timer and consume the key press with 'return true'.
You can then exit the app within the timer tick event. A 4 second delay will probably be long enough.
 
Top