我在火力地堡上做循环和新的我不接收来自火力地带/ Firestore Itry的数据以从我的keyValue获取数据

时间:2019-06-14 14:27:27

标签: android google-cloud-firestore

在firebase中,我的文档是日期和 我要逐日检查一个月(通过我的文档)是否有数据,如果可以,请给我一天有数据

数据库:收集营养->失效日期(dd-mm-yyyy)

在没有循环的情况下,它会工作到getNutritionFromFb(date,dateNum,Foods.BREAKFAST);

但是在循环中它不会进入

你可以看我在做什么...

for (int i = 0; i <= maxDay; i++) {

    if (i < 10) {
        date = "0" + i + "-" + monthFromNum + "-" + year;
        dateNum = "0" + i + "-" + monthFromNum + "-" + year;
    } else {
        date = i + "-" + monthFromNum + "-" + year;
        dateNum = i + "-" + monthFromNum + "-" + year;
    }


    getNutritionFromFb(date, dateNum, Foods.BREAKFAST);
    getNutritionFromFb(date, dateNum, Foods.LUNCH);
    getNutritionFromFb(date, dateNum, Foods.DINNER);
    getNutritionFromFb(date, dateNum, Foods.SNACK);
}


private void getNutritionFromFb(final String date, final String dateNum, final String nutritionType) {
    db.collection(Foods.NUTRITION).document(FireBaseInit.getEmailRegister()).collection(nutritionType)
            .document(date).collection(Foods.All_NUTRITION).get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {

                    if (task.isSuccessful() && Objects.requireNonNull(task.getResult()).getDocuments().size() > 0) {

                        Log.d(TAG, "have nutrition in this data: " + date);

                        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.US);

                        try {
                            Date mDate = sdf.parse(dateNum);
                            long timeInMilliseconds = mDate.getTime();

                            calenderEvent.addEvent(new Event(timeInMilliseconds, "Nutrition", Color.GREEN));


                        } catch (ParseException e) {
                            Log.i(TAG, "error: " + e);
                        }
                    }
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.i(TAG, "Filed receive data " + e);
                }
            });
}

我在日志中没有错误,编译器没有进入firebase检查数据

1 个答案:

答案 0 :(得分:0)

您没有得到任何日志

if (task.isSuccessful() && Objects.requireNonNull(task.getResult()).getDocuments().size() > 0) {
         Log.d(TAG, "task is successfull ");               
    }
    else{
     Log.d(TAG, "task not successfull ");
    }