getExternalCacheDir() returns null after clearing data

前端 未结 3 1262
忘了有多久
忘了有多久 2021-02-07 04:45

I have a simple app that access and writes data to external storage. Everything works fine until I go to Settings -> Apps -> App Info and clear data via \"Clear data\" button, t

3条回答
  •  清歌不尽
    2021-02-07 05:03

    I have encountered and solved this exact problem.

    Clicking the Clear Data button causes Android to stop your app from running and delete the entire application-specific folder "mnt/sdcard/Android/data/your.package.name" .

    However, I had a separate process that was started from Runtime.getRuntime().exec() that was still running and it was writing to this folder. This caused the folder to be stuck in a locked state and caused the same symptom you described when my app called getExternalCacheDir() . Running adb shell and then ls from within the /mnt/sdcard/Android/data folder showed that the folder was locked by a process. Running ps showed that my other process was still running.

    The solution was to properly kill the other process that was still writing to my application's application-specific folder before calling getExternalCacheDir() .

提交回复
热议问题