I only have this issue when I set external storage (which I need for my app as it saved images to gallery). Certain files saved by my game a few months ago will keep coming back even after uninstalling the app and reinstalling it. Upon uninstall you can see that they all get deleted fine in the Android/data/… folder, along with all the app data. But then upon re-install they pop back out of nowhere, as if there was some mechanism that would recover deleted app data from some cache folder that is stored elsewhere, some automatic default mechanism that I don’t know of. The recovered app files include specific images, screenshots from the game saved months ago so no way does my code add them back, it has to be sitting somewhere outside of the persistentdata path, a place that Android uses to recover data from on reinstall. It could also be a Unity recovery mechanism.
Found the cause of the problem (took me a whole day though):
It’s due to an auto-backup feature since Android 6.0. All your app data is automatically backed up to your linked Google account. You can find the back up in your Google Drive. By default the backed up data will be restored upon reinstall. I turned off Wifi on my dev phone for a while and only turned it back on recently, that’s why I had this weird experience of files haunting me from the past all of a sudden.
Solution:
-
If it bothers you too during development (as the saved data structure may change across builds), you can just turn it off in Cloud And Accounts / Backup And Restore / Automatic Restore.
-
You can also disable auto backup for your app entirely by adding android:allowBackup=“false” to your androidmanifest.xml file inside the application statement. Make sure to add this to the manifest file at Asset/Android/Plugins, this is how you tell Unity to merge your modifications with its auto-built manifest. In case you don’t have it there yet, copy the one from Temp/StagingArea after a build.
Include This At
Assets/Plugin/Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<application android:allowBackup="false" tools:replace="android:allowBackup">
</application>
</manifest>
I added the code. It's just the Collision Detection in OnCollisionEnter2D. There's a DOShakeScale inside that.
– B-R-JI tried this but data is still getting recovered.
I tried changing device resolution at runtime for performance but took out the code as it wasn’t needed.
However, the device gets the down scaled resolution every time. If WiFi is off, the resolution is correct but it’s the wrong resolution when WiFi is on
First of all thank you so much for this. Saved me another day of work trying to figure it out. Secondly, you didn't write what should be added to the manifest... And lastly: in my Android device the location of that specific setting is in Settings -> Backup and Reset -> Automatic restore. Thanks again :)
– amoswazana