Open benstraats opened 6 years ago
More specifics: In login.java theres a function called onCreate. This function is called whenever this page opens, which is when the app initially opens since its the first page. Inside this function you should attempt to load the saved users credentials from the phones memory described in the link above.
Case 1: IF there is something in memory then call the login function with the username and password you retrieved.
IF the login attempt succeeds then there's nothing else you need to do, everything is already setup. On a successful login the onSuccess function inside the login function will be called. IF the login attempt fails then you have to wipe the saved credentials from memory. On a failed login the onFailure function inside the login function will be called
Case 2: IF there is nothing in memory then do nothing at the start in onCreate.
Once the user does a successful login then save the credentials to the phones memory. This should be done in the onSuccessfull callback of the login function. Note: signing up calls the login function once its done signing up so dont worry about the special case when they sign up
Once the user logs in successfully we should save that users username and password to the phones local memory.
Then, when the app is opened the next time we should read that users username and password from the phone and automatically try to log them in.
If the username and password isn't in the memory, then just open the app normally (aka go to the login page)
If the username and password is in the memory and the login call works, automatically bring them to the landing (main) page.
If the username and password is in the memory and the login call fails, wipe the info from memory and start the app normally (aka just go to the login screen)
Use this article for reference on how to read/write to the phones private memory: https://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Note, there is a better way but its super confusing and unnecessary for now. Before we release we'll be switching over to it (its called AccountManager for android)