I am using firebase. I want to check for duplicate data for my application. Currently I am letting user to enter name and email. But if the user enters the same name and email for the second time it also get added to database. how to solve this Here is my code:
package com.example.zaid_pc.mpd2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
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 tournament extends AppCompatActivity {
private EditText etTournament;
private EditText emailTournament;
private DatabaseReference mDatabaseRefernce;
Button btnTournament;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tournament);
etTournament = (EditText)findViewById(R.id.etTournament);
emailTournament = (EditText)findViewById(R.id.emailTournament);
btnTournament = (Button)findViewById(R.id.btnTournament);
mDatabaseRefernce = FirebaseDatabase.getInstance().getReference().child("People Registered");
btnTournament.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String name = etTournament.getText().toString().trim();
final String email = emailTournament.getText().toString().trim();
//mDatabaseRefernce.child("Name").setValue(name);
//mDatabaseRefernce.child("Email").setValue(email);
final DatabaseReference peopleRegisered = mDatabaseRefernce.push();
peopleRegisered.child("Name").setValue(name);
peopleRegisered.child("Email").setValue(email);
Toast.makeText(tournament.this, "You will be notified via email", Toast.LENGTH_LONG).show();
finish();
}
});
}
}