I need to save a pressed button id the first time the app is executed. I have an Activity with two buttons that take you to one new activity (there are 2 profiles,like user and supervisor). I would like to save button id the first time that my app is running on the device, so in next executions you don't need to select the profile again. Is that possible?
This is my SelectionActivity code:
class SeleccionarPerfilActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_seleccionar_perfil)
val btnHijo: Button = findViewById(R.id.botonhijo)
val btnTutor: Button = findViewById(R.id.botonmadre)
btnHijo.setOnClickListener{onClick(btnHijo.id}
btnTutor.setOnClickListener{onClick(btnTutor.id}
}
fun onClick(id:Int) {
when(id){
R.id.btnHijo-> {
val intent=Intent(this,MenuHijoActivity::class.java)
startActivity(intent)
}
R.id.btnTutor-> {
val intent=Intent(this,MenuTutorActivity::class.java)
startActivity(intent)
}
}
}
Firstly, store your id with onClick method using by SharedPreferences. After that, retrieve that id in onCreate method and check if that id is null. If it's null, display your buttons, if not call your onClick method by your retrieved id.