How to avoid duplicate data in Firebase Database
<p>In my Android application I am inserting a VideoEntity objects in firebase database this way: </p>

<pre><code>@Override
    protected void onCreate(Bundle savedInstanceState){

        Log.d(TAG, " onCreate(Bundle) - Ini ");
        super.onCreate(savedInstanceState);

        database =  FirebaseDatabase.getInstance();
        String videoId = "";

        for(VideoEntity video: videosList) {
            videoId = video.getId();
            DatabaseReference mRef =  database.getReference().child("Videos").push();
            mRef.setValue(video);
        }
</code></pre>

<p>this the VideoEntity class:</p>

<pre><code> package com.app.entities;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;

public class VideoEntity implements Parcelable{

    private String id;
    private String title;
    private String description;
    private String thumbnailURL;
    private String category;



    public VideoEntity() {

    }

    public VideoEntity(Parcel in) {
        id = in.readString();
        title = in.readString();
        description = in.readString();
        thumbnailURL = in.readString();
        category = in.readString();

    }



    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getThumbnailURL() {
        return thumbnailURL;
    }

    public void setThumbnailURL(String thumbnail) {
        this.thumbnailURL = thumbnail;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCategory() {return category;}

    public void setCategory(String category) { this.category = category;}

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeString(id);
        dest.writeString(title);
        dest.writeString(description);
        dest.writeString(thumbnailURL);
        dest.writeString(category);
    }

    public static final Creator&lt;VideoEntity&gt; CREATOR = new Creator&lt;VideoEntity&gt;() {
        @Override
        public VideoEntity createFromParcel(Parcel in) {
            return new VideoEntity(in);
        }

        @Override
        public VideoEntity[] newArray(int size) {
            return new VideoEntity[size];
        }
    };
}
</code></pre>

<p>The problem is that everytime I start this activity the same objects are inserted in the database, so i have duplicate data in the database.</p>

<p>Is there anyway to avoid this ?</p>