Cancel preference change

Is there a way to undo a change in preferences before actually executing it?

The priority of the changed listener allows me to see the changes, but does not allow me to undo it. In some cases, I need to show the user AlertDialog so that he can undo the change. Is there an easy way to do this?

+3
source share
1 answer

I think you can control the change, since it is saved only after calling the commit function

SharedPreferences prefs = getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("somevalue", true);
editor.commit();

You can view the value with a toast or something else before you name the commit. or yes / no.

0
source

All Articles