月份:2022 年 10 月

Android 6 種資料儲存方法總結說明
前幾篇文章介紹了在 Android 開發中,使用的各種資料儲存方式。Android 資料儲存方式包含:Resource Files、Internal Storage、External Storage、SharedPreferences、SQLite 資料庫及 Room 資料庫。

Android Room 資料庫使用方法
Room 持續性資料庫為 SQLite 提供抽象層,可讓資料庫更順暢的存取,同時充分發揮 SQLite 的效用,由於 SQLite API 存在一些缺點,因此 Google 強烈建議使用 Room 來存取 SQLite 資料庫中的資料。

Android SQLite 資料庫使用方法
SQLite 是一種輕量化的關聯式資料庫,適合用來儲存複雜且重複的結構化資料,如果您熟悉 SQL 資料庫,那麼使用 SQLite 必定能駕輕就熟,使用上大同小異。目前 Android 已經內建 SQLite ,無需安裝任何套件,也無需任何權限就能使用。

Android SharedPreferences 使用方法
SharedPreferences 是一種輕量化的 Key-Value 資料儲存方式,適合用來儲存簡單輕量的資料,例如使用者帳號、暱稱、登入時間...等等。如果是複雜格式的資料,則建議使用 JSON 檔案或 SQLite 資料庫儲存。

Android External Storage 外部儲存使用方法
External Storage 中的檔案能與其他 APP 共享資源,也可以使用手機內建的檔案管理 APP 來瀏覽這些檔案。由於 External Storage 儲存設備可能被使用者移除,因此比較適合用來儲存 APP 執行時非必要的檔案,就是被刪除也不影響 APP 執行的檔案。