D DT1111 Member Licensed User Longtime User Jun 23, 2014 #1 Hi 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? Code: Copy 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 Code: Copy Sub Activity_Pause (UserClosed As Boolean) If UserClosed then File.Delete(File.DirRootExternal,"1.txt") end if end sub
Hi 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? Code: Copy 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 Code: Copy Sub Activity_Pause (UserClosed As Boolean) If UserClosed then File.Delete(File.DirRootExternal,"1.txt") end if end sub
lemonisdead Well-Known Member Licensed User Longtime User Jun 23, 2014 #2 Hello, If it is on KitKat I do remember the subject was discussed by Erel previously : http://www.b4x.com/android/forum/th...on-external-sd-with-kitkat.37592/#post-223941 Upvote 0
Hello, If it is on KitKat I do remember the subject was discussed by Erel previously : http://www.b4x.com/android/forum/th...on-external-sd-with-kitkat.37592/#post-223941
LucaMs Expert Licensed User Longtime User Jun 23, 2014 #3 DT1111 said: What is wrong? Click to expand... Nothing Upvote 0
LucaMs Expert Licensed User Longtime User Jun 23, 2014 #4 lemonisdead said: Hello, If it is on KitKat I do remember the subject was discussed by Erel previously : http://www.b4x.com/android/forum/th...on-external-sd-with-kitkat.37592/#post-223941 Click to expand... So, you can't delete AND can't write files on other dir than DirDefaultExternal. Nice KitKat (food for cats or chocolate? ) Upvote 0
lemonisdead said: Hello, If it is on KitKat I do remember the subject was discussed by Erel previously : http://www.b4x.com/android/forum/th...on-external-sd-with-kitkat.37592/#post-223941 Click to expand... So, you can't delete AND can't write files on other dir than DirDefaultExternal. Nice KitKat (food for cats or chocolate? )
NJDude Expert Licensed User Longtime User Jun 23, 2014 #5 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. Upvote 0
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.
D DT1111 Member Licensed User Longtime User Jun 24, 2014 #6 Thank you all for the link and inputs. 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. Click to expand... 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 Code: Copy 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 Code: Copy 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 Upvote 0
Thank you all for the link and inputs. 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. Click to expand... 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 Code: Copy 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 Code: Copy 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
D DT1111 Member Licensed User Longtime User Jun 24, 2014 #7 Hi Erel I was reading the blogs as suggested by lemonisdead : http://www.b4x.com/android/fo...on-external-sd-with-kitkat.37592/#post-223941 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 nothing to solve or that can be solved. It is explained here: http://source.android.com/devices/tech/storage/index.html If you want to write to a removable external card then you can only write to a folder based on your package name. File.DirRootExternal / DirDefaultExternal continue to work properly. Click to expand... This is how Google designed Android 4.4: https://plus.google.com/ TodLiebeck/posts/gjnmuaDM8sn Starting from Android 4.4 you can only write to a folder based on your package name (on SD cards). Click to expand... Apologies if I had quoted you out of context Upvote 0
Hi Erel I was reading the blogs as suggested by lemonisdead : http://www.b4x.com/android/fo...on-external-sd-with-kitkat.37592/#post-223941 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 nothing to solve or that can be solved. It is explained here: http://source.android.com/devices/tech/storage/index.html If you want to write to a removable external card then you can only write to a folder based on your package name. File.DirRootExternal / DirDefaultExternal continue to work properly. Click to expand... This is how Google designed Android 4.4: https://plus.google.com/ TodLiebeck/posts/gjnmuaDM8sn Starting from Android 4.4 you can only write to a folder based on your package name (on SD cards). Click to expand... Apologies if I had quoted you out of context
Erel B4X founder Staff member Licensed User Longtime User Jun 24, 2014 #8 Apologies if I had quoted you out of context Click to expand... This is indeed the case here. Apologies accepted 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. Upvote 0
Apologies if I had quoted you out of context Click to expand... This is indeed the case here. Apologies accepted 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.
D DT1111 Member Licensed User Longtime User Jun 24, 2014 #9 Sweet. I know where the problem is. 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. Thanks Erel. Last edited: Jun 24, 2014 Upvote 0
Sweet. I know where the problem is. 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. Thanks Erel.