SQLite data persisting after uninstall on Android?

Chris_HChris_H NZMember ✭✭

I have a Xamarin Forms app that stores user data in an SQLite database, including login information. Up until recently, uninstalling the app on Android would wipe the database clean and reinstalling it would be as if doing a fresh install. However, for some reason data is now persisting between installs, so that I can uninstall the app, reinstall it (via a Debug deployment) and when I open in the user is still logged in. I've verified that the login token is actually being read out of the SQLite database, so the data is definitely still there. Another strange behaviour is that I can log out in my app (which deletes the token from the database) and if I reopen the app normally the user is still logged out, but if I do another Debug deploy the data in the database mysteriously reverts and they are logged in again. It's almost as if there are now two databases on the device.

So far I'm unable to pinpoint the cause of this in any release notes (I haven't made any code changes related to it), have there been any recent changes that would account for it?

Tagged:

Best Answers

  • Chris_HChris_H NZ ✭✭
    Accepted Answer

    Some more information:

    This happens on both Release and Debug builds, on both Android and iPhone.

    I'm initializing my SQLiteConnection like this (on Android):

           var sqliteFilename = "mydatabase.db3";
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder
            var path = Path.Combine(documentsPath, sqliteFilename);
            var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
    
            var conn = new SQLite.Net.SQLiteConnection(platform, path);
    
            // Return the database connection 
            return conn;
    

    It appears rather than just persisting between installs, there is a stale copy of the database which is somehow being installed whenever I install the app. I have one .db3 file with the same name in the project in the res/raw folder, of size 0 bytes, but other than that I have no idea where the stale data is coming from. I've searched through the .apk can can't see any .db3 file in there with the stale data in it. I can log out (which wipes the whole database), then reinstall the app and this old data is back.

  • Chris_HChris_H NZ ✭✭
    Accepted Answer

    Setting android:allowBackup="false" in the application tag in AndroidManifest.xml fixed the problem. It seems that for some weird reason the Android OS was restoring from a backup every time I deployed the app.

Answers

  • Chris_HChris_H NZMember ✭✭
    Accepted Answer

    Some more information:

    This happens on both Release and Debug builds, on both Android and iPhone.

    I'm initializing my SQLiteConnection like this (on Android):

           var sqliteFilename = "mydatabase.db3";
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder
            var path = Path.Combine(documentsPath, sqliteFilename);
            var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
    
            var conn = new SQLite.Net.SQLiteConnection(platform, path);
    
            // Return the database connection 
            return conn;
    

    It appears rather than just persisting between installs, there is a stale copy of the database which is somehow being installed whenever I install the app. I have one .db3 file with the same name in the project in the res/raw folder, of size 0 bytes, but other than that I have no idea where the stale data is coming from. I've searched through the .apk can can't see any .db3 file in there with the stale data in it. I can log out (which wipes the whole database), then reinstall the app and this old data is back.

  • Chris_HChris_H NZMember ✭✭
    edited April 2017

    Sorry, I did not mean to mark that as an accepted answer. Is there any way to unaccept it?

  • Chris_HChris_H NZMember ✭✭
    Accepted Answer

    Setting android:allowBackup="false" in the application tag in AndroidManifest.xml fixed the problem. It seems that for some weird reason the Android OS was restoring from a backup every time I deployed the app.

  • FabioGiacomelliFabioGiacomelli USMember ✭✭

    it works! great solution, thank you

  • android:allowBackup="false"
    does not work for me... even if I delete the cache and the data before uninstall the app.

Sign In or Register to comment.