因此,我想从Firestore数据库中获取数据,并将其与在Actions.java文件中定义的对象一起放入数组列表。 数据库参考是正确的。 数据库中的对象正确。 但是该程序会同时跳过OnSucsess和OnFailure侦听器。 可能是什么原因造成的?
public class Activity_edit_actions extends AppCompatActivity {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference notebookRef = db.collection("actions");
private ArrayList<Action> actionList = new ArrayList<Action>();
List<Action> userActionsList;
private ActionAdapter adapter;
Context context = this;
CollectionReference userDbRef = db.collection("users").document(FirebaseAuth.getInstance().getCurrentUser().getEmail()).collection("actions");
CollectionReference dbRef = db.collection("actions");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_edit_actions);
getUserActions();
setUpRecyclerView();
}
private void setUpRecyclerView() {
Query query = notebookRef.orderBy("priority", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Action> options = new FirestoreRecyclerOptions.Builder<Action>()
.setQuery(query, Action.class)
.build();
adapter = new ActionAdapter(options, actionList);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
public void addActionsToLocal(){
TinyDB tinydb = new TinyDB(context);
}
public void getUserActions(){
userDbRef.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Action action = documentSnapshot.toObject(Action.class);
actionList.add(action);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("redebug", "onFailure: Retrieving user actions from db failed");
}
});
}
}