回答編集履歴
4
PreferenceManegarについて追記
answer
CHANGED
@@ -21,4 +21,22 @@
|
|
21
21
|
|
22
22
|
```
|
23
23
|
|
24
|
-
androidx.core.content.editの関数内に`apply()`(引数によって`commit()`を選択することも可)が実装されているため、ユーザーが記述するソースでは改めて`apply()`や`commit()`を記述する必要はありません。
|
24
|
+
androidx.core.content.editの関数内に`apply()`(引数によって`commit()`を選択することも可)が実装されているため、ユーザーが記述するソースでは改めて`apply()`や`commit()`を記述する必要はありません。
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
> 共有プリファレンスが非推奨コードになっているとのことだったので
|
29
|
+
|
30
|
+
これについても、AndroidXライブラリーによる`PreferenceManager`の利用が推奨されるようになったことによるものです。build.gradle(:app)のdependenciesブロックに
|
31
|
+
|
32
|
+
```gradle
|
33
|
+
implementation 'androidx.preference:preference:1.1.1'
|
34
|
+
```
|
35
|
+
|
36
|
+
を追加し、kotlinソースファイルでは
|
37
|
+
|
38
|
+
```kotlin
|
39
|
+
import androidx.preference.PreferenceManager
|
40
|
+
```
|
41
|
+
|
42
|
+
のようにandroidxに改めることによって、非推奨を表す取り消し線を消すことができるでしょう。(ちなみに質問に記述されたPreferenceManegarは誤スペルですね)
|
3
リンク追加
answer
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
ベストアンサー後なのですが、`edit {}`のような記法はAndroid KTXの拡張機能であり、`SharedPreferences#edit()`とは別関数です。
|
2
2
|
|
3
|
+
[Android KTX | Android Developers](https://developer.android.com/kotlin/ktx?hl=ja)
|
3
4
|
[androidx.core.content#edit | Android Developers](https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#edit)
|
4
5
|
|
5
6
|
この関数を利用するためには、まずbuild.gradle(:app)に以下の記述を追加します。
|
2
修正
answer
CHANGED
@@ -20,4 +20,4 @@
|
|
20
20
|
|
21
21
|
```
|
22
22
|
|
23
|
-
androidx.core.content.editの関数内にapply()が実装されているため、ユーザーが記述するソースでは改めて`apply()`や`commit()`を記述する必要はありません。
|
23
|
+
androidx.core.content.editの関数内に`apply()`(引数によって`commit()`を選択することも可)が実装されているため、ユーザーが記述するソースでは改めて`apply()`や`commit()`を記述する必要はありません。
|
1
微修正
answer
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
ベストアンサー後なのですが、`edit {}`のような記法はAndroid KTXの機能であり、`SharedPreferences#edit()`とは別関数です。
|
1
|
+
ベストアンサー後なのですが、`edit {}`のような記法はAndroid KTXの拡張機能であり、`SharedPreferences#edit()`とは別関数です。
|
2
2
|
|
3
|
-
[androidx.core.content | Android Developers](https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#edit)
|
3
|
+
[androidx.core.content#edit | Android Developers](https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#edit)
|
4
4
|
|
5
|
-
この
|
5
|
+
この関数を利用するためには、まずbuild.gradle(:app)に以下の記述を追加します。
|
6
6
|
|
7
7
|
```gradle
|
8
8
|
android {
|