I am writing an android application where I want to integrate facebook login using facebook sdk 3.I have tried lots of tutorial but now successful.Can anyone give me a
complete guide by which I can achieve following :
Login activity:
If user logs in once from this activity it will go to home activity.Guess user has logged in for the first time and now on home activity and after few moments user has closed the app. From now every time user starts the app, app will skip the login activity and starts home activity. If user changes his password from facebook.com and then starts the android app then I want to show the login activity.
Home activity:
I have a logout button on this activity.
Thanks in advance.
Facebook is holding that value in session,
So you have to just check that is_session_valid()
or not and base on that response you can switch your activity.
You can store login status (true / false) in sharedPreferences. Now for second requirement two cases may occur.
When user left the HomeActivity, the app goes in background it is alive but is in passive state, In this case you don't need to do anything when user relaunches App from recent tasks or from launcher Android will automatically start the last Activity user viewed (i.e. HomeActivity in your case).
While the App was in background someone killed it i.e. Android OS for claiming memory for some other App, you restarted phone, some task killer killed App etc. In that case when user starts App again, Android will start the default launcher Activity i.e. LoginActivity their you need to check the variable you stored in SharedPreferences inside OnResume of LoginActivity. If user was already logged in just start the HomeActivity else start the normal behavior.
Not just the boolean variable you can store anything you think will be needed for starting HomeActivity.
The key here is to keep track of tokens and see if the token is still valid. If token is not valid the user need to login again. So when you request a token for the first time save it in the user defaults of the application. And just check next time for validity of the token.
See here for login specific information:
https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/
For more information see at chapter 6
https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/