Tried to create another activity and put same code in it but still had "null" in result.Had problem only with one specific kotlin Activity. Also google it and cant find answer. with rest activities no such problem with same Intent put extra code.
**Noticed that if I set activity startActivity from 'A' to 'C' I can get Intent with same code. But If A>B>C than on 'C' activity I get null from 'A' activity **
class GenderActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_gender_qstn)
val btn: Button = findViewById(R.id.btnNextGender)
val radioG: RadioGroup = findViewById(R.id.radioGroupD)
btn.setOnClickListener {
val i = Intent(this, GoalsActivity::class.java)
i.putExtra("sex", "some text")
startActivity(i)
}
}
private lateinit var database: DatabaseReference
class QuizActivity2 : AppCompatActivity() {
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_quiz2)
val btnAddUser = findViewById<Button>(R.id.buttonAddUser)
val muscles = intent.getStringExtra("muscles").toString()
val gender:String = intent.getStringExtra("sex").toString()
val goal = intent.getStringExtra("goal")
val textOn:TextView = findViewById(R.id.textViewQst2)
btnAddUser.setOnClickListener{
val userName = findViewById<EditText>(R.id.inputUserName).text.toString()
val userAge = findViewById<EditText>(R.id.inputUserAge).text.toString()
if(userAge.isEmpty()||userName.isEmpty()){
Toast.makeText(
this,
"заповни всі поля",
Toast.LENGTH_SHORT
).show()
}
if(userAge.isNotEmpty()&&userName.isNotEmpty()){
database = FirebaseDatabase.getInstance().getReference("Users")
val userId = database.push().key!!
data class User(val firstName:String? = null,val userGender:String? = null,val age:String? = null,val uId:String? = null,val muscles:String? = null,val goals:String? = null)
val user = User(userName,gender,userAge,userId,muscles,goal)
textOn.text = user.toString()
database.child(userName).setValue(user).addOnSuccessListener {
findViewById<EditText>(R.id.inputUserName).text.clear()
findViewById<EditText>(R.id.inputUserAge).text.clear()
}
}
}
}
}