1
\$\begingroup\$

After the use uninstall/reinstalls my app, all of his serialized data is gone. Is there a way to store a file on a mobile device permanently - which persists through various installs? Without using a server/cloud service or requiring the user to log into Google Play Games?

\$\endgroup\$
1
\$\begingroup\$

If you delete an app on a mobile device, its data is gone.

If you want to retain data between uninstalls, the data will need to be saved on a server.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer! This comment I found seems to think otherwise: stackoverflow.com/a/19683766/4177440 but I don't really understand it. Are you still sure it is not possible? \$\endgroup\$ – Georgi Sep 7 '17 at 0:13
  • \$\begingroup\$ It's possible that data might be retained for a little while, but should not be treated as a reliable source - it's up to the operating system. What if the user formats their device? The data will surely be gone. Saving the data off the device is the only way. Android SD card might work if you can find a way (I'm not familiar with this though), but what if the user does not have an SD card? \$\endgroup\$ – Chris McFarland Sep 7 '17 at 3:51
1
\$\begingroup\$

For those reading, I found this genius piece of code (first snippet): https://forum.unity3d.com/threads/load-video-files-from-sd-card.477593/ which I used to write my data to the phone's sdcard. It remained after completely un- and re-installing the app! Eureka! Now only to figure out how to do this on IOS...

UPDATE: still haven't tried IOS but improved it so it works with Internal Memory and no sdcard (but you need "Write External Storage" permission still for some reason):

     string s = Directory.GetParent(
                     Directory.GetParent(Application.persistentDataPath)
                         .Parent.Parent.FullName).FullName;

     if (!Directory.Exists(s + "/.GAMENAME/"))
         Directory.CreateDirectory(s + "/.GAMENAME/");

     myPath = s + "/.GAMENAME/GAMENAME.save";
\$\endgroup\$
  • \$\begingroup\$ I suggest you ask your users the permission to do this before doing it. They could assume that removing your game would actually remove your game and not pollute their device. \$\endgroup\$ – Vaillancourt Sep 7 '17 at 23:52
0
\$\begingroup\$

Generally, the answer isn't that you can't, it's that you shouldn't create application specific data on a device that remains after removing the application. Otherwise the data of previous apps will uselessly stay on the device indefinitely, until it slowly fills up all of the device's storage. This is extremely bad form and may result in your app being rejected from the store.

You need to distinguish between files that belong to the device, such as music, photos, ... , and files that belong to the application, such as savegames. This applies regardless of mobile or not. The convention on desktop OSes is that during uninstall you ask the user if they want to keep their savegames.

How to do store data on the device is OS specific, so for an actual example you'll need to specify the OS.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the awesome advice! Is there a source somewhere regarding whether my app will be rejected from the store if it does this? Also, I'm targeting IOS/Android. \$\endgroup\$ – Georgi Sep 7 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.