---
title: "Undo and redo PDF annotations on Android | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/android/features/undo-redo/"
md_url: "https://www.nutrient.io/guides/android/features/undo-redo.md"
last_updated: "2026-05-23T00:08:17.979Z"
description: "Nutrient Android SDK supports undo and redo for creating and editing annotations. Control UndoManager functions, and use PdfConfiguration to enable/disable these features."
---

# Undo and redo annotations on Android

Nutrient Android SDK supports undo and redo for creating and editing annotations. Users can undo and redo changes using the buttons in [`AnnotationToolbar`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui.toolbar/-annotation-toolbar/).![Undo and Redo](@/assets/guides/android/features/undo-redo/undo-redo.gif)

To achieve this, we’ve created an interface named [`UndoManager`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/index.html). The implementation of this interface is provided through the `PdfFragment#getUndoManager()` method. The [`UndoManager`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/index.html) provides methods for controlling the undo/redo business logic, including:

- [`undo()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/undo.html) — undo the last performed edit

- [`redo()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/redo.html) — redo the last undone edit

- [`canUndo()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/can-undo.html) — whether or not the undo action can be executed

- [`canRedo()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/can-redo.html) — whether or not the redo action can be executed

## Enabling/disabling undo and redo

Undo and redo operations are enabled by default. However, you can use [`undoEnabled(boolean)`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration/-pdf-configuration/-builder/undo-enabled.html) and [`redoEnabled(boolean)`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration/-pdf-configuration/-builder/redo-enabled.html) when building a [`PdfConfiguration`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration/-pdf-configuration/) to control whether or not undo and redo are enabled or disabled in your app. Logically, redo cannot be enabled if undo is disabled.

## Listening for undo and redo changes

To listen for undo and redo changes, you can attach [`OnUndoHistoryChangeListener`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-on-undo-history-change-listener/) to the [`UndoManager`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/index.html) through [`addOnUndoHistoryChangeListener()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/add-on-undo-history-change-listener.html). The callback will notify you once the undo history changes so that you can update the UI or components that need to be aware of the undo/redo state.

## Intercepting edits

To intercept editing operations to read details or to block adding to the undo stack, implement the [`OnAddNewEditListener`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-on-add-new-edit-listener/) interface and add it to the [`UndoManager`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.undo/-undo-manager/index.html) to get notified when edits are about to be added.

Here’s an example that blocks annotation creation from being added to the undo stack:

```kotlin

class MyActivity : PdfActivity(), OnAddNewEditListener {

    override fun onDocumentLoaded(document: PdfDocument) {
        super.onDocumentLoaded(document)
        // Hook listener to the SDK.
        pdfFragment?.undoManager?.setOnAddNewEditListener(this)
    }

    override fun onAddNewEdit(edit: Edit): Boolean {
        // This override blocks an edit that is triggered from adding an annotation.
        // It allows every other edit operation to be added to the undo stack.
        return!(edit is AnnotationAddRemoveEdit && edit.type == AnnotationAddRemoveEdit.Type.ADD_ANNOTATION)
    }
}

```

## Current limitations

- Currently, undo/redo history is tracked for annotations and content editing operations.
---

## Related pages

- [Define annotation behavior with flags on Android](/guides/android/annotations/annotation-flags.md)
- [Embed or attach a file to a PDF on Android](/guides/android/annotations/file-annotations.md)
- [Set annotation author names on Android easily](/guides/android/annotations/annotation-author-name.md)
- [Programmatically create annotations on Android](/guides/android/annotations/programmatically-creating-annotations.md)
- [Disabling annotation editing on Android](/guides/android/annotations/configuring-annotation-editing.md)
- [Z-Index for annotation stacking order on Android](/guides/android/annotations/annotation-z-index.md)
- [Copy and paste annotations on Android](/guides/android/features/copy-paste.md)
- [Detect if an annotation has changed on Android](/guides/android/annotations/create-edit-and-remove/detect-changes.md)

