0

For my android application I'm using the "sharedPreferences" to save the logIn password and some other data. I have the following problem:

When I install my APK and I create an account the LogIn data are saved with sharedPreferences. After deleting my application and reinstalled I can still use the old password.

Is there any possibility to remove what ever is saved through sharedPreferences? My last question is, is the method to save my LogIn Password with sharedPreferences a good technique or I should use something else?

Thank you in advance!

Evangelos
  • 15
  • 6
  • As far as i know `sharePreferences` won't work. `sqlite` works well for it –  Jan 27 '21 at 20:03
  • 2
    See https://stackoverflow.com/questions/15873066/how-to-remove-shared-preference-while-application-uninstall-in-android In particular, you may need to use application tag `android:allowBackup="false"` – Jems Jan 27 '21 at 20:06

2 Answers2

1

As far as I know, It's a good way to use SharedPreferences when you need to save Login Password, Now coming to your main question, You might have android:allowBackup="true" in your manifest, Try passing "False" instead

Update

Just for your information, SharedPreferences deletes the info on uninstallation.

0

You can use something like this to clear your sharedPreferences.

SharedPreferences sharedPreferences = context
                        .getSharedPreferences(context
                        .getResources()
                        .getString(<<YOUR_NAME>>), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.commit();

About your second question, you can persist login and password in SharedPreferences, but its good to create a security sharedPreference.

And if you have to persist some complex data and objects, you can use Room Database to do it.

Here's a Room database link