tags:

views:

25

answers:

1

I notice that my app's data on external storage (i.e. SD card) gets deleted during an "adb install -r". While this is normal for uninstall (and then afterwards install optionally to notice it), I do not understand why this is the case for reinstall (and thus for Market updates as well). I could have sworn this was not always the case.

Referring to http://developer.android.com/guide/topics/data/data-storage.html#filesExternal I am specifically using "Accessing files on external storage" on Android 2.2, but not "Saving files that should be shared" or "Saving cache files". So I am writing and reading data in "/sdcard/Android/data//files/somefolder/data". My preferences do stick.

@Commonsware: The problem is not so much with getExternalFilesDir() IMHO as I see my data is written where I expect it. It just does not stick. I am using a.o.:

public static File getDefaultDirectory(Context context, String packageName) {
    File dir;
    if(mActivity_getExternalFilesDir!=null){//API >=8
        dir = invokeGetExternalFilesDir(context, "fortune");
    }else if(mEnvironment_getExternalStorageDirectory!=null){//API <=7
        dir = invokeGetExternalStorageDirectory();
        dir = new File(dir.getPath() + "/Android/data/" + packageName + "/files/");
    }else{
        //should never occur
        return null;
    }
    return dir;
}
+1  A: 

IIRC, there is a bug in Android 2.2 that causes these symptoms. I advise against the use of getExternalFilesDir() until Gingerbread.

CommonsWare
Thanks Mark. Could you post a link to more info? Or an issue number? Cannot find it...
pjv
@pjv: http://groups.google.com/group/android-developers/browse_thread/thread/b68d40b1f13e12df?pli=1
CommonsWare
That's it! Though there is a good chance this will also be in Android 2.2.1 (the update for the Nexus One), looking at the submitted patch.
pjv
Actually it does not seem to be in 2.2.1 either. Will have to wait for Gingerbread indeed.
pjv