I’m writing login capability using share preference. I use SharedPreferences.Editor::commit() to store username and password; read it from shared_prefs to check login. After logging in, I cd to /data/data/com.< my_package >/shared_prefs/ and remove the “shared_prefs” folder. The problem is the application screen is still in login status. I tried to Back and restart the application but it’s still in login status. Does removing the “shared_prefs” by hand clear the prefs completely? Why is my app still in login status?
I’m writing login capability using share preference. I use SharedPreferences.Editor::commit() to store username and
Share
You shouldn’t be removing the preferences folder. The behavior of the shared preferences is undocumented if you do this. (Even if you exit the last activity, the process may still be alive and the previously read preferences still in memory.)
If you want to delete specific values from shared preferences, use
SharedPreferences.Editor.remove(String). If you want to clear out all values, useSharedPreferences.Editor.clear(). In either case thencommit()your changes for them to take effect.If you want to reset your program to its initial state (as if it has never run), go to Settings -> Manage Applications, open your application, stop it (if it is running), and then clear all data.