Android/kotlin/singleton
提供: 初心者エンジニアの簡易メモ
2020年2月14日 (金) 13:46時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「==singletonサンプル== MainActivity.kt HogeSingleton.setName("hogehoge") Log.i("test", "HogeSingleton.getName()=" + HogeSingleton.getName()) // hogehoge HogeSinglet...」)
singletonサンプル
MainActivity.kt
HogeSingleton.setName("hogehoge")
Log.i("test", "HogeSingleton.getName()=" + HogeSingleton.getName()) // hogehoge
HogeSingleton.kt
class HogeSingleton {
companion object {
private var name = ""
fun setName(name: String) {
this.name = name
}
fun getName(): String {
return this.name
}
}
}
