Skip to content Skip to sidebar Skip to footer

How To Implement Undo/redo And Preserve The Value On Orientation Change In Android Edittext?

I am using the TextViewUndoRedo class for undo/redo operations and it works but I want the value preserved after orientation/onConfigurationChange. There are two methods in that c

Solution 1:

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
  super.onSaveInstanceState(savedInstanceState);
  SharedPreferences sp = getSharedPreferences("unforedopref", 0);

  mTextViewUndoRedo.storePersistentState(sp.edit(), "undoredokey");
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);

  SharedPreferences sp = getSharedPreferences("unforedopref", 0);
  mTextViewUndoRedo.restorePersistentState(sp, "undoredokey");
}

You need to save and restore state in lifecycle methods of your activity


Post a Comment for "How To Implement Undo/redo And Preserve The Value On Orientation Change In Android Edittext?"