I enabled the skip login, wherein I am not able to get the email of the account I was logged in to.
How can I still get the email if skip login is enabled in the second launch of the app?
I enabled the skip login, wherein I am not able to get the email of the account I was logged in to.
How can I still get the email if skip login is enabled in the second launch of the app?
2
Answers
While launching the app first time, after login you can save the username and email in Shared Preference and on second time launch you can fetch it. First initialize App Preference using method
Then set userName and use it.
Code is shared below
The Firebase authentication state persists across application restarts. So there is no need to save the email address locally in order to use it again when you restart the application. As soon as you create an instance of the FirebaseAuth class, you can call getCurrentUser() which:
As you can see, the type object that is returned is FirebaseUser. If this object is null it means that your user is not logged in, otherwise, you can call FirebaseUser#getEmail(). In this way, you can always get the email address from this object, without the need to perform any other operations.
If you want to track the auth state, then I recommend you check my answer from the following post:
If you want to see a real example, please check this resource, with the corresponding repo.