Application.persistentDataPath returns wrong path if it's launcher app

I’m developing an app that can be set as the default launcher in Android. Users were reporting that most of the times (but not always?), after rebooting their phone and the app was launched automatically by the system, they were losing their data and the app was behaving like it was the first launch. However, after restarting the app, their data was back, and everything was working fine.

After some investigation, we discovered that the Application.persistentDataPath was different if the app was opening as the launcher app automatically after the reboot.

This corresponds to the getFilesDir() path of the app. However, according to the Unity docs, Application.persistentDataPath should correspond to getExternalFilesDir(). Which is, indeed, the path that my app uses if it’s launched regularly (not by the system during reboot):

Does anyone know why this mismatch occurs? Is this an issue within Unity or on my side? Thanks!

1 Like

Hi Karuzo, I’m facing the same issue with default launcher app in Unity 2021.3, do you have any work-around for this?
Currently I have to point exactly to external SD card path on first launch.

I’m facing a closely related issue. It happens when launching the game immediately after rebooting the Android device, when the system is still slow and everything is loading.

Path when starting the app immediately after reboot:

/data/user/0/...

Path when starting the app normally:

/storage/emulated/0/Android/data/...

When the problem occurs and the savegame seems to be gone, killing the app and restarting it fixes the issue.

I still find it very concerning because players will think that their save was deleted when it happens. Also, nothing prevents the user from continuing to play on the new/wrong savegame…