I received a crash saying that it was caused by calling getCurrentUser()
. Here's the relevant part of the crash logs from Crashlytics:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.c.f com.google.android.gms.common.api.e.b(com.google.android.gms.common.api.internal.aj)' on a null object reference
at com.google.android.gms.internal.zzdvv.zzb(Unknown Source)
at com.google.android.gms.internal.zzdwc.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.getCurrentUser(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.getCurrentUser(Unknown Source)
at <my.app.package>.<class1>.isUserNull(Unknown Source)
at <my.app.package>.<class2>.requestUserLogin(Unknown Source)
I'm using the MVP architecture for my app and the corresponding Firebase function was called in a helper class. The structure/flow looks like this:
Activity > Presenter > Interactor > Helper
As soon as the activity starts, it initializes the presenter, which initializes the interactor, which initializes the helper class. The helper class looks like this:
public class Helper{
private FirebaseAuth mAuth;
public Helper(@NonNull Listener){
mAuth = FirebaseAuth.getInstance();
}
public boolean isUserNull(){
return mAuth.getCurrentUser() == null;
}
}
As visible in the helper class, FirebaseAuth is properly initialized, so calling getCurrentUser()
should be safe.
getCurrentUser()
returns either a FirebaseUser
or null, so I believe having a user currently signed in or not doesn't matter at all in this scenario.
We already did testing on our end and never experienced this before, which is why this is very confusing. Adding to it, among the dozens of users so far, this is the only instance that it happened.
Has anyone experienced something similar to this before or has any idea what could've caused it?
I'm considering changing the function to just directly get the FirebaseAuth instance like this:
public boolean isCurrenUserNull(){
return FirebaseAuth.getInstance().getCurrentUser() == null;
}
But I'm not really sure if that would change anything.
Update: In response to Bob Snyder's answer/comment
The app currently starts with an initial activity that checks for the necessary requirements for the app, like for Google Play Services requirement. If it fails, it closes, if it doesn't it then checks if there is an already existing user via the getCurrentUser()
function. This is probably where the error is happening for some reason.
With regards to "message receipt, notification intent.." -- FCM is currently implemented and it is possible to receive notifications, that when tapped, the user would be directed to the corresponding activity.
However, for that to work, the user should be able to go past the initial sign at least once, and should be kept signed in. Otherwise, they would no longer receive notifications (I'm handling the logout as I posted here).
And thinking about it, if FCM does work immediately, doesn't that make sure that Google Play Services is already up-to-date?
Thoughts and suggestions are highly appreciated!