対象ケース
- アプリをアンインストールをして再インストールしてもデータが残っている気がする
- アンインストール前に設定->アプリから
ストレージを消去
をしてるのに再インストール時にデータが残っている気がする
android:allowBackup="false"
が必要
Android 6.0 (API 23)からデフォルトで有効になっているAuto Backupがtrueになっているかもしれません。
AndroidManifest.xml
を確認してみてください。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shanonim.sample">
<application
android:name=".SampleApp"
android:allowBackup="false"
RoomもAuto Backupの対象
デフォルトのAuto Backup対象ファイルは次のとおりです。(引用元: Back up user data with Auto Backup)
By default, Auto Backup includes files in most of the directories that are assigned to your app by the system:
- Shared preferences files.
- Files saved to your app's internal storage, accessed by getFilesDir() or getDir(String, int).
- Files in the directory returned by getDatabasePath(String), which also includes files created with the SQLiteOpenHelper class.
- Files on external storage in the directory returned by getExternalFilesDir(String).
Roomはそもそも、Android Architecture Componentsの中で「SQLiteを扱いやすくするための機能」として提供されています。つまり、上記の対象ファイル説明の中でalso includes files created with the SQLiteOpenHelper class.
と説明されている部分にRoomで作成したデータベースも含まれているようです。
Roomを使っている、かつAuto Backupを使用する必要のない場合は、android:allowBackup
を確認してみましょう。
参考リンク
- Remove room database on app uninstall
https://stackoverflow.com/questions/49677497/remove-room-database-on-app-uninstall