Android Question Auto restore user data after app reinstall

stu14t

Active Member
Licensed User
Longtime User
I'm trying to implement this : Back up user data with Auto Backup

My app generates a UUID during the first install to uniquley identify the device. However, if the user does a full reainstall then a new UUID will be created.

In my app, on first install a UUID is saved and the backed up to a KVS in the preferences. My understanding this is held in an xml file (i;ve called mine AppPrefs and I want that backedup perminently so on reinstall this infromation is recovered and the same UUID used.

I do understand the user can turn this off.

At the moment I've added this to the manifest :


B4X:
SetApplicationAttribute(android:allowBackup, "true")
SetApplicationAttribute(android:fullBackupContent, "@xml/backup_rules")

and I'm trying to add the following backup_rules.xml :


B4X:
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="AppPrefs.xml"/>
</full-backup-content>

I've tried adding this to the res/xml folder but it keep getting deleted on each build

Am I on the right track or is there a better way to do this?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. KVS creates a SQLite db. This means that by default there will be 1 db file and possibly another 2 journal files (you can change the pragma to DELETE to always have a single file: https://www.b4x.com/android/forum/threads/b4x-sql-setting-the-journal-mode.136211/#content)

2. You shouldn't create the res\xml file yourself. You should do it with the manifest editor:
B4X:
CreateResource(xml, backup_rules.xml,
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="AppPrefs.xml"/>
</full-backup-content>
)

I'm not familiar with this "full backup content" feature.
 
Upvote 0

stu14t

Active Member
Licensed User
Longtime User
Thanks Erel,

I'll need to modify that XML file to make sure it backs up the SQLite database.
 
Upvote 0
Top