Skip to content Skip to sidebar Skip to footer

Adding List To Cloud Firebase - Android

I do everything according to great guides from Youtube. https://www.youtube.com/watch?v=W-L6Cr2WP18 - I recommend. Unfortunately, instead of activity, I use a fragment and I have a

Solution 1:

To solve this, change the following lines of code:

if(googleSignInAccount != null){
    StringuserEmail= googleSignInAccount.getEmail();
    StringuserName= googleSignInAccount.getDisplayName();
    Toast.makeText(this, "Witaj " + userName, Toast.LENGTH_LONG).show();
}

with

if(googleSignInAccount != null){
    userEmail = googleSignInAccount.getEmail();
    userName = googleSignInAccount.getDisplayName();
    Toast.makeText(this, "Witaj " + userName, Toast.LENGTH_LONG).show();
}

This fields are already declared as global.

You are using in your fragment the following line of code:

dailyGoalsRef = rootRef.collection("goalsData").document(userEmail).collection("dailyGoals");

Where the userEmail is null. This is happening because you are not passing the userEmail from the activity to the fragment. Just declaring it as a global variable does not solve the problem.

To solve this, create a method in your activity that returns the userEmail.

publicStringgetUserEmail() {return userEmail;}

And in your fragment, create a String field String userEmail as global and call that method like this:

userEmail = ((MainActivity) getActivity()).getUserEmail();

Post a Comment for "Adding List To Cloud Firebase - Android"