Android: Saving to SD Card always deletes on re-install
I am using the get开发者_StackOverflowExternalFilesDir(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!
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.
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.
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.
精彩评论