views:

61

answers:

3

I am using the getExternalFilesDir(null) method to save to the SD card. Saving and reading from the SD card is fine. The problem I am having is that every time I edit anything in Eclipse and rerun the app the data on the SD card is deleted. I know that saving to the directory returned by getExternalFilesDir(null) will allow the files there to be deleted when my app is uninstalled but is there a way to turn it off for just app updating? Is this only cause I am doing it from Eclipse and it won't delete the data when the app is updated from the market? Thanks for any info you can give me!

+2  A: 

This is a bug in Android 2.2. Patches will become available over the next few months for 2.2 devices. You may wish to hold off using this feature until the next Android OS update.

CommonsWare
Thanks for the answer. So where on the SD card should I save files? Is there a standard to follow?
Corey Alexander
@Corey Alexander: there is no current standard, other than putting stuff in a directory (so you don't clutter up the SD card root).
CommonsWare
A: 

if you do require the data, why don't you try renaming the package. In that case you may be left with multiple copies of the application but I think your data still remains intact.

Shouvik
A: 

From what I read elsewhere the current standard of the month is a subdirectory in /sdcard/Android. i.E.:

final java.io.File Storage = android.os.Environment.getExternalStorageDirectory ();
final java.io.File Dir = new java.io.File (Storrage, "Android/" + getPackageName ());
Dir.mkdirs ();

We can only hope that the bug is fixed very soon.

Martin
I think this where the file is saved getExternalFilesDir(null). So if I save to the place you recommend I think I would get the same bug just indirectly.
Corey Alexander
No, getExternalFilesDir(null) gives you: "Android/data/" + getPackageName ()Note the "data" part. if you use that directory ("Android/data") then the files will be deleted even if you did not actually use getExternalFilesDir(null) to get/create the directory.Trust me i tried it all.
Martin