Hi, I create a temporary file at run-time which I want to delete on exit. I catch the back button event in the code below. If the user confirms the exit (pressing "Yes"), I want to delete the temporary file. Pressing "No" returns the user to the current page. However, when "Yes" is pressed, the app main page is displayed as expected but the file is still present in the sub folder. Can anyone tell me why and what I should do? Thanks.
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
MyTable.SaveTableToCSV(File.DirRootExternal & "/abc/def/" ,"TempTable.csv")
closeCounter = closeCounter + 1
Log("closeCounter = " & closeCounter)
If closeCounter < 2 Then
If Msgbox2("Do you really want to exit", "Exit", "Yes", "No", "", Null)=DialogResponse.Cancel Then
closeCounter = 0
Log("closeCounter is = " & closeCounter)
Return True
Else
closeCounter = 0
If File.Delete(File.DirRootExternal, "/abc/def/TempTable.csv")=True Then
ToastMessageShow("file deleted", True)
End If
Return False
End If
End If
End If
End Sub