I'm implementing a chat function in my app using firebase. I followed a tutorial to the letter and I'm not sure why the real-time database is not updating as the requests are being made. It says firebase is connected in the codebase. The implemented code is standard for requesting and pushing data to the realtime database. Would appreciate some insight on where the logic is failing in the sendMessage and addValueEventListener
package com.example.groupin;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class chatActivity extends AppCompatActivity {
private DatabaseReference myDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
myDatabase = FirebaseDatabase.getInstance().getReference("Message");
TextView myText = (TextView) findViewById(R.id.textView8);
myDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
myText.setText(dataSnapshot.getValue().toString());
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
myText.setText("CANCELLED");
}
});
}
public void sendMessage(View view){
EditText myEditText = (EditText) findViewById(R.id.editTextTextPersonName);
myDatabase.setValue(myEditText.getText().toString());
myEditText.setText("");
}
}
why this chat won't workwhat doesn't work ? what's it doing/not doing ? - a_local_nobody