Reputation: 113
I have my onCreate in my LoginActivity like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
if(currentUser!= null) {
currentUserId = currentUser.getUid();
}
But my variable, when I install for the first time my app, currentUserId is null. why? how can I solve it?
Upvotes: 2
Views: 1404
Reputation: 139039
when I install for the first time my app, currentUserId is null... why?
That's the expected behavior since the user is not authenticated the first time it installs/opens the app. FirebaseAuth's getCurrentUser() methods:
Returns the currently signed-in FirebaseUser or null if there is none.
So as seen above, if you get null, the user is not authenticated. To get the actual FirebaseUser object, authenticate the user with one of the available options/prividers, and that object won't be null anymore.
Upvotes: 2