Reputation: 23
This video shows exactly what I mean. Firebase stores data.
The video is: https://www.youtube.com/watch?v=DCg00fe-_xs
After the 6th second of the video, trying to enter new data, the data stays about a second in Firebase, but automatically then it disappears.
I try to input the data into Firebase two more times in this video, but the data always automatically disappears afterwards.
You can see that the other data that is stored in Firebase does NOT disappear. But the data of this code is automatically disappearing for some reason as shown in the video. Please what can I do to fix it?
Code:
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String raça = spinner_raca.getSelectedItem().toString();
final String regiaoDoEstado = spinner_regiaoDoEstado.getSelectedItem().toString();
final String estado = spinner_estado.getSelectedItem().toString();
Intent receiverIntent = getIntent();
Bundle bundleRecebedor = receiverIntent.getExtras();
String nomecompleto = bundleRecebedor.getString("nomecompleto");
String email = bundleRecebedor.getString("email");
String doencasPreExistentes = bundleRecebedor.getString("doencasPreExistentes");
String dataDeNascimento = bundleRecebedor.getString("dataDeNascimento");
String genero = bundleRecebedor.getString("genero");
String identificadorEmHash = bundleRecebedor.getString("identificadorEmHash");
String telefone = receiverIntent.getStringExtra("telefone");
reference = FirebaseDatabase.getInstance().getReference().child("Usuarios").child(identificadorEmHash);
Toast.makeText(getApplicationContext(), identificadorEmHash, Toast.LENGTH_LONG).show();
if(identificadorEmHash.equals(null)) {
Toast.makeText(getApplicationContext(), "The identifier does not exist", Toast.LENGTH_LONG).show();
} else {
reference.addListenerForSingleValueEvent(new ValueEventListener() {
// reference.addValueEventListener(new ValueEventListener() {
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
reference = FirebaseDatabase.getInstance().getReference().child("Usuarios").child(identificadorEmHash);
if (!dataSnapshot.exists()) {
Toast.makeText(getApplicationContext(), "The identifier does not exist", Toast.LENGTH_LONG).show();
} else {
HashMap<String, String> sendDataToDataBase = new HashMap<>();
sendDataToDataBase.put("Nome Completo", nomecompleto);
sendDataToDataBase.put("E-mail", email);
sendDataToDataBase.put("Identificador em Hash", identificadorEmHash);
sendDataToDataBase.put("Telefone", telefone);
sendDataToDataBase.put("Doenças Pré Existentes", doencasPreExistentes);
sendDataToDataBase.put("Data de Nascimento", dataDeNascimento);
sendDataToDataBase.put("Gênero", genero);
// // When I am going to send the following data to Firebase, the problem of the video happens.
sendDataToDataBase.put("Região do Estado em que mora", regiaoDoEstado);
sendDataToDataBase.put("Raça", raça);
sendDataToDataBase.put("Estado do Brasil em que mora", estado);
try {
raiz.child(identificadorEmHash).setValue(sendDataToDataBase);
} catch (Exception e) {
e.getMessage();
}
Intent senderIntent = new Intent(getApplicationContext(), MainActivity0.class);
senderIntent.putExtra("nomecompleto", nomecompleto);
senderIntent.putExtra("email", email);
senderIntent.putExtra("doencasPreExistentes", doencasPreExistentes);
senderIntent.putExtra("dataDeNascimento", dataDeNascimento);
senderIntent.putExtra("genero", genero);
senderIntent.putExtra("raça", raça);
senderIntent.putExtra("estado", estado);
senderIntent.putExtra("regiaoDoEstado", regiaoDoEstado);
senderIntent.putExtra("identificadorEmHash", identificadorEmHash);
senderIntent.putExtra("telefone", telefone);
startActivity(senderIntent);
// Toast.makeText(getApplication(), "Success!", Toast.LENGTH_LONG).show();
}
Toast.makeText(getApplicationContext(), identificadorEmHash, Toast.LENGTH_LONG).show();
}
});
}
}
});
Please, what to do to fix the problem shown on the video?
Upvotes: 0
Views: 78
Reputation: 137
You are calling MainActivity0 at the end of the code. The problem can be there
Upvotes: 1