Frontend Engineer
Storeとなるクラスを定義
package com.example.cameraxapp.lib import android.app.Application class GlobalStore: Application() { var userId: String = "" companion object { private var instance : GlobalStore? = null fun getInstance(): GlobalStore { if (instance == null) instance = GlobalStore() return instance!! } } }
ボタンが押されたらeditTextの文字をグローバル変数に格納する例
viewBinding.buttonNext.setOnClickListener { val store = GlobalStore.getInstance() store.userId = viewBinding.editTextUserId.text.toString() }
Storeとなるクラスを定義
package com.example.cameraxapp.lib import android.app.Application class GlobalStore: Application() { var userId: String = "" companion object { private var instance : GlobalStore? = null fun getInstance(): GlobalStore { if (instance == null) instance = GlobalStore() return instance!! } } }
ボタンが押されたらeditTextの文字をグローバル変数に格納する例
viewBinding.buttonNext.setOnClickListener { val store = GlobalStore.getInstance() store.userId = viewBinding.editTextUserId.text.toString() }