基本上,我想获取一个字符串变量,然后检查我的Firebase数据库节点之一,以查看该字符串的子代是否存在,如果存在,我希望将特定于该字符串的值添加到我的数据库中,但是执行不会一个接一个地执行,循环不会总是等待整个检查字符串是否在数据库中作为子代存在,它有时会跳过它,因此应该添加的值并不全都是被添加
我正在
上在单独的线程上运行此操作 count = i;
Elements mShowUpdateName = doc.select("div[class=data main]").select("b").eq(i);
mUpdateName = mShowUpdateName.text();
Elements mShowEpisodeDate = doc.select("div[class=data main]").eq(i);
mEpisodeDate = mShowEpisodeDate.text();
int startIndex = mUpdateName.indexOf("-");
mSeriesName = mEpisodeDate.substring(0,startIndex-1);
Log.e("child" , mSeriesName);
usersTVSeriesRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String mString = mSeriesName.replace(".", "");
if(dataSnapshot.hasChild(mString)){
int first = mEpisodeDate.indexOf("-");
int second = mEpisodeDate.indexOf("-", first + 1);
String season = mEpisodeDate.substring(first+1, second);
second = mEpisodeDate.indexOf("-", first + 1);
int last = mEpisodeDate.lastIndexOf("-");
String episode = mEpisodeDate.substring(second+1, last);
int startIndexDate = mEpisodeDate.indexOf("[");
int endIndexDate = mEpisodeDate.lastIndexOf("]");
String date = mEpisodeDate.substring(startIndexDate +1 , endIndexDate);
HashMap<String, Object> showsMap = new HashMap<>();
showsMap.put("date" , date);
showsMap.put("episode" , episode);
showsMap.put("season", season);
showsMap.put("string", mEpisodeDate);
showsMap.put("index", Integer.toString(count));
showsMap.put("name", mSeriesName);
updateRef.child(mString).child(episode).updateChildren(showsMap);
}
else {
Log.e("no", "no new updates");
Log.e("no", mSeriesName);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
我希望它始终检查数据库中是否存在该值,然后相应地执行
当前日志为
E/loop: Step 1. String: Will And Grace
E/loop: Step 1. String: The Grand Tour
E/loop: Step 1. String: The Good Fight
E/loop: Step 1. String: Hanna
E/loop: Step 1. String: What We Do in the Shadows
E/loop: Step 2. checking if the value exists in the database
Step 3. value doesn't exist
Step 2. checking if the value exists in the database
E/loop: Step 3. value doesn't exist
Step 2. checking if the value exists in the database
Step 3. value doesn't exist
E/loop: Step 1. String: Jane The Virgin
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. adding value to database
E/loop: Step 1. String: Chicago PD
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. adding value to database
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. adding value to database
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. adding value to database
我想要的是始终遵循第1、2、3步
E/loop: Step 1. String: Chicago Med
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. adding value to database
E/loop: Step 1. String: Chicago Fire
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. adding value to database
E/loop: Step 1. String: MotherFatherSon
E/loop: Step 2. checking if the value exists in the database
E/loop: Step 3. value doesn't exist