Can’t retrieve data from cloud firestore firebase

  android, firebase

I send data from the activity to the cloud firestore and I retrieve it in the second activity in recycler view.
but the data doesn’t appear in the second activity.

I used FirestoreRecyclerAdapter and FirestoreOptions.

This is the activity in which I retrieve the data.

public class MyServicesActivity extends AppCompatActivity {
private FirestoreRecyclerAdapter adapter;
private RecyclerView recyclerView;
private FirebaseFirestore db;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_services);

    db = FirebaseFirestore.getInstance();
    Query query = db.collection("Services Requested");
    recyclerView = findViewById(R.id.rv_my_services);

    FirestoreRecyclerOptions<ServiceModel> response = new FirestoreRecyclerOptions
            .Builder<ServiceModel>()
            .setQuery(query, ServiceModel.class)
            .build();

    adapter = new FirestoreRecyclerAdapter<ServiceModel, ServiceHolder>(response) {


        @NonNull
        @Override
        public ServiceHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.service_design, parent, false);
            return new ServiceHolder(v);
        }

        @SuppressLint("SetTextI18n")
        @Override
        protected void onBindViewHolder(@NonNull ServiceHolder holder, int position, @NonNull ServiceModel model) {
            holder.serviceImage.setImageResource(model.getServiceImage());
            Log.d("DATA", "data isn't null" + position);
            holder.serviceName.setText(model.getServiceName());
            holder.servicePrice.setText(model.getPrice() + "" + " L.E");
        }


    };


    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));


}

public class ServiceHolder extends RecyclerView.ViewHolder {

    private ImageView serviceImage;
    private TextView serviceName, servicePrice;

    public ServiceHolder(@NonNull View itemView) {
        super(itemView);
        serviceImage = itemView.findViewById(R.id.polish_img);
        serviceName = itemView.findViewById(R.id.polish_txt);
        servicePrice = itemView.findViewById(R.id.price_txt);
    }
}

@Override
protected void onStart() {
    super.onStart();
    adapter.startListening();
}

@Override
protected void onStop() {
    super.onStop();
    adapter.startListening();
}
}

Firebase cloud firestore dashboard

Source: Android Questions

LEAVE A COMMENT