I'm working on an app that uses Firebase authentication to sign in users through phone number. I want to add a functionality such that there is only one-time login for the user, i.e. even if the user kills the app and starts it again, he should be logged in. Also, I don't want to add a logout feature. What can be done for this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
This is from my working code from logging class:
The simplest way to achieve this is to use a listener. Let's assume you have two activities, the
LoginActivity
and theMainActivity
. The listener that can be created in theLoginActivity
should look like this:This basically means that if the user is logged in, skip the
LoginActivity
and go to theMainActivity
.Instantiate the
FirebaseAuth
object:And start listening for changes in your
onStart()
method like this:In the
MainActivity
, you should do the same thing:Which basically means that if the user is not logged in, skip the
MainActivity
and go to theLoginActivity
. In this activity you should do the same thing as in theLoginActivity
, you should start listening for changes in theonStart()
.In both activities, don't forget to remove the listener in the moment in which is not needed anymore. So add the following line of code in your
onStop()
method:You can save user login session in shared Preference
Do this when your login got Login Success
and When Your apps is Starts (like Splash or login Page) use this
It will works for you.