-2
I’m making a task app with Kotlin and firebase, but every time I try to add information to my database, it doesn’t add it but replaces the previous one.
This is my code:
class AddActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add)
}
fun function4(view: View){
val uid = FirebaseAuth.getInstance().uid ?: ""
val ref = FirebaseDatabase.getInstance().getReference("users/$uid-posts")
val user2 = AddActivity.User2(editText3.text.toString(), editText4.text.toString())
ref.setValue(user2)
val intent2 = Intent(this, TasksActivity::class.java)
intent2.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK.or(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent2)
}
class User2(val title: String, val content: String)}
This answers your question? create a new Child with the same name instead of overwriting-firebase
– tvdias