LoginSignup
6
4

More than 5 years have passed since last update.

Roomを使ったAndroidアプリをアンインストールしてもデータが残っている気がする

Posted at

対象ケース

  • アプリをアンインストールをして再インストールしてもデータが残っている気がする
  • アンインストール前に設定->アプリからストレージを消去をしてるのに再インストール時にデータが残っている気がする

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を確認してみましょう。

参考リンク

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4