0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Kotlin 初心者】Preferencesの使い方

Last updated at Posted at 2021-04-15

Preferences

API通信したアプリのtokenなどのデータをローカルに保存させます

参考URL
https://developer.android.com/guide/topics/ui/settings/use-saved-values?hl=ja

Preferencesに書き込む

val shardPreferences = this.getPreferences(Context.MODE_PRIVATE)
val shardPrefEditor = shardPreferences.edit()

shardPrefEditor.putString("token", token)
shardPrefEditor.apply()

Preferencesで読み取る

val shardPreferences = this.getPreferences(Context.MODE_PRIVATE)
var data = shardPreferences.getString("token", "[]")
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?