Log in once and skip the login layout each time the application starts after the first login

I am writing an Android application where I want to integrate my facebook login using facebook sdk 3. I have tried many tutorials, but now successfully. Can someone give me a complete guide with which I can achieve the following results:

  • Input Activity:

    If a user logs in once from this action, he switches to home activity. The user automatically logged in for the first time and is now in home activity, and after a few minutes the user closed the application. Now, when the user launches the application, the application skips login activity and starts active work. If the user changes his password from facebook.com and then launches the Android application, I want to show login activity.

  • Main activity:

    I have a button to exit this activity.

Thanks in advance.

+4
source share
3 answers

Facebook holds this value in a session,

So, you just need to check that is_session_valid() or not, and based on this answer you can switch your activity.

+1
source

You can save the login status (true / false) in sharedPreferences . Now for the second requirement, two cases may arise.

  • When the user exits HomeActivity , the application will be in the background in live mode, but in a passive state, in this case you do not need to do anything when the user restarts the application from recent tasks or from the Android launcher automatically starts viewing the last action (i.e. e. HomeActivity in your case).

  • While the application was in the background, someone killed , that is, Android OS to approve memory for some other application, you restarted the phone, killed some task killers, etc. In this case, when the user starts the Application again, Android will launch the default launch action, i.e. LoginActivity , you need to check the variable stored in SharedPreferences inside OnResume of LoginActivity. If the user has already logged in, just start HomeActivity to start normal behavior.

Not only a boolean variable in which you can store anything , you will need to launch HomeActivity .

+1
source

The key here is to keep track of tokens and see if the token is really valid. If the token is invalid, the user needs to log in again. Therefore, when you request a token for the first time, save it in the user default values โ€‹โ€‹of the application. And just check the next time the token expires.

See login information here: https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/

See chapter 6 for more details https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

0
source

Source: https://habr.com/ru/post/1480649/


All Articles