I have two fragments. The first one get data from firebase, and the second one use the data. I am setting the data bundle using the setArguments() in first fragment and consuming it using getArguments in the second fragment. But i get a null value when consuming it. The below are the fragments.
FirstFragment;
firebaseFirestore.collection("QuizList")
.document(quizId).collection("Results")
.document(currentUserId).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if(task.isSuccessful()){
DocumentSnapshot result = task.getResult();
Long correct = result.getLong("correct");
Long wrong = result.getLong("wrong");
Long missed = result.getLong("unanswered");
resultCorrect.setText(correct.toString());
resultWrong.setText(wrong.toString());
resultMissed.setText(missed.toString());
//Calculate Progress
Long total = correct + wrong + missed;
Long percent = (correct*100)/total;
ListFragment listFragment = new ListFragment();
Bundle bundle = new Bundle();
bundle.putLong("total", total);
bundle.putLong("percent", percent);
listFragment.setArguments(bundle);
resultPercent.setText(percent + "%");
resultProgress.setProgress(percent.intValue());
}
}
});
SecondFragment:
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Bundle bundle = this.getArguments();
if (bundle != null) {
Long total = getArguments().getLong("total", 0);
Long percent = getArguments().getLong("percent",0);
Toast.makeText(getActivity(),String.valueOf(total),Toast.LENGTH_SHORT).show();
}
}
any help to do that? thank you!