I thought the file will be deleted when the app exits ie when the UserClosed flag is true. But that is not the case.
What is wrong?
B4X:
Sub Activity_Create(FirstTime As Boolean)
If File.Exists(File.DirRootExternal,"1.txt") = False Then
File.OpenOutput(File.DirRootExternal,"1.txt",False)
End If
end sub
B4X:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed then
File.Delete(File.DirRootExternal,"1.txt")
end if
end sub
There are 2 kinds of SD cards, Internal and External, the original poster is dealing with the internal (File.DirRootExternal).
The code works, however, you are creating that file on Activity_Create if doesn't exists, so this is what I see, you exit the activity and gets deleted, re-open the app (or return to the activity) and it's created again.
The code works, however, you are creating that file on Activity_Create if doesn't exists, so this is what I see, you exit the activity and gets deleted, re-open the app (or return to the activity) and it's created again.
Granted the logic of sequence will recreate the "1.txt" but what I did was before relaunching the app, I checked if the "1.txt" was deleted after exiting the app, with FileManager. No it wasn't deleted. The point is the presence of the file was not the result of re-creation when the app is relaunched but rather the app was not deleting it upon exit.
I have changed my approach ie without deleting it but instead writing to it but that doesn't seem to work either
B4X:
Sub Activity_Create(FirstTime As Boolean)
If File.Exists(File.DirRootExternal,"1.txt") = False Then
File.OpenOutput(File.DirRootExternal,"1.txt",False)
File.WriteString(File.DirRootExternal,"1.txt","Hello World")
End If
end sub
B4X:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed then
File.OpenOutput(File.DirRootExternal,"1.txt",False)
File.WriteString(File.DirRootExternal,"1.txt","Goodbye World")
end if
end sub
The following were mentioned and I am trying to understand if writing to File.DirRootExternal (ie not SD card) will continue to work properly or was it superseded by KitKat.
And if I understand it correctly, writing to a folder based on package name is only applicable if one is writing to an SD card. In my case I am not.
There is no problem with writing or deleting files on the main "external storage" (File.DirRootExternal / DirDefaultExternal). The restriction is relevant to a real sd card only.
I thought the UserClosed flag will fire when I exit the app by first selecting the "cascading" icon in the Android navigation button (the right most) and ending the app by swiping it away. No that didn't work.
But when I close the app correctly by selecting the end application navigation button (the left most), then the code works.