How to prevent data on external storage getting deleted on reinstall/update?
<p>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.</p>

<p>Referring to <a href="http://developer.android.com/guide/topics/data/data-storage.html#filesExternal" rel="nofollow">http://developer.android.com/guide/topics/data/data-storage.html#filesExternal</a> 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.</p>

<p>@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.:</p>

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