'how to specify to not backup default sharedPreference and database with android:dataExtractionRules?

I want to not backup sharedPref as those contains login info. I'm using below code to not allow backup for API > android12.

 <cloud-backup>
    <exclude domain="sharedpref" />
    <exclude domain="database" />
</cloud-backup>
<device-transfer>
    <exclude domain="sharedpref" />
    <exclude domain="database" />
</device-transfer>

Is this enough to prevent backing up of default sharedPref and any room db?

What is the best way / what else should I do to prevent that backup?



Solution 1:[1]

In your manifest add

<application
android:allowBackup="false"
android:fullBackupContent="false"
android:dataExtractionRules="@xml/data_extraction_rules"
tools:targetApi="s">

The data extraction rules must be

<data-extraction-rules>
<cloud-backup>
    <exclude domain="database" />
    <exclude domain="sharedpref" />
</cloud-backup>
<device-transfer>
    <exclude domain="database" />
    <exclude domain="sharedpref" />
</device-transfer>

Maybe this link might help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1