Question

I am new to android environment and have been trying my hands on different things in android. I don't know whether this is possible or not, but I want to achieve some sort of functionality as follow:

when my app starts, the main activity allows the user to login using facebook or Google. I have used Facebook SDK for login and logout functionality for facebook. (I am still using deprecated methods)

Now when user logins using either facebook or google , I want my app to automatically navigate to other activity.

Question 1: How should I do this ? using both Facebook and Google?

This activity has four buttons. Using these , user can navigate to different parts of the App. One of these buttons is Settings. Whenever user clicks on this button, the App should show the profile information of the user. The information that my First Activity gathers when it prompts the user to login.

Question 2: How should I manage user data from their accounts between different activities?? (like their email or Profile picture etc)

Question 3: Should i access the data in first login activity or when user clicks on the "Setting " button? (in the next activity) Is it possible? how? I think I can use Access Tokens like (getAccessToken() in facebook sdk??) that i get in first activity?

Question 4: Can i save the data when user first logs in, so that i don't have to fetch the data every time he logs in? How should I do this?

And between one session (Login and logout) I don't want my app to fetch data everytime he user clicks on "Settings" button..... how should i save data? SharedPreferences ??

Any sort of Comments, Remarks (Related only) , Articles, tutorials, projects , views, suggestions are most welcome!! I am quite confused. thankyou!!

Was it helpful?

Solution

Question 1: How should I do this ?

Use an Intent to go to the next Activity on successful login.

Question 2: How should I manage user data from their accounts between different activities?? (like their email or Profile picture etc)

Store the details in SharedPreferences when the user logs in and make sure to clear the SharedPreferences on logout.

Question 3: Should i access the data in first login activity or when user clicks on the "Setting " button? (in the next activity) Is it possible? how? I think I can use Access Tokens like (getAccessToken() in facebook sdk??) that i get in first activity?

Question 4: Can i save the data when user first logs in, so that i don't have to fetch the data every time he logs in? How should I do this?

And between one session (Login and logout) I don't want my app to fetch data everytime he user clicks on "Settings" button..... how should i save data? SharedPreferences ??

Yes, SharedPreferences is the solution to these. Here is something you could do :

  • when the user logs in for the first time, store the access tokens and their expiry in SharedPreferences.

  • after that, every time, just check if the session is valid or not by using the access tokens. If session is valid, then use the details stored in your Preference file. If the session has expired, fetch the tokens again and update your SharedPreference file.

Here is an excellent video tutorial series on Android Facebook SDK and the best part for you is that he uses SDK 2.0 (the deprecated one), like you are using!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top