---
title: "Extending PdfActivity with custom activities"
canonical_url: "https://www.nutrient.io/guides/android/customizing-the-interface/extending-pdfactivity/"
md_url: "https://www.nutrient.io/guides/android/customizing-the-interface/extending-pdfactivity.md"
last_updated: "2026-06-05T20:16:40.074Z"
description: "Displaying documents using the PdfActivity is sufficient in most cases. Nonetheless, there are situations where customizations beyond pure styling are necessary."
---

# Extending PdfActivity with custom activities

Displaying documents using the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) is sufficient in most cases. Nonetheless, there are situations where customizations beyond pure styling are necessary. For more flexibility, you can extend the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) and implement your own custom activities.

Since a `PdfActivity` and any activities deriving from it need special intent data (document sources, passwords, configuration, etc.) you need to create a special launch `Intent` using the [`PdfActivityIntentBuilder`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity-intent-builder/index.html) that will carry all of this information. The builder allows you to set your activity class using its [`#activity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity-intent-builder/activity-class.html) method. For a comprehensive example of what is possible with customization, take a look at the `CustomLayoutExample` or the `CustomActionsExample` inside the Catalog app.

## Creating your activity

The first step for implementing a custom activity is to subclass the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html). Note that your custom activity does not need to override `#onCreate`, and it does not need to define or inflate a layout. The layout will be set up by the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) parent class and can be using the [`PdfActivityConfiguration.Builder#layout`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration.activity/-pdf-activity-configuration/-builder/layout.html) when launching the activity:

### MYCUSTOMACTIVITY.KT

```kt

class MyCustomActivity : PdfActivity() {

    override fun onPrepareOptionsMenu(menu: Menu): Boolean {
        var handled = super.onPrepareOptionsMenu(menu)

        // Custom action bar menu creation.

        return handled
    }

    override fun onDocumentLoaded(document: PdfDocument) {
        // Document is ready to use.
    }

    override fun onDocumentLoadFailed(exception: Throwable) {
        // Add your fancy error handling here.
    }
}

```

### MYCUSTOMACTIVITY.JAVA

```java

public class MyCustomActivity extends PdfActivity {

    @Override public boolean onPrepareOptionsMenu(Menu menu) {
        boolean handled = super.onPrepareOptionsMenu(menu);

        // Custom action bar menu creation.

        return handled;
    }

    @Override public void onDocumentLoaded(PdfDocument document) {
        // Document is ready to use.
    }

    @Override public void onDocumentLoadFailed(Throwable exception) {
        // Add your fancy error handling here.
    }
}

```

Next, you need to add this activity to your `AndroidManifest.xml` so you can launch it. You can also define the `android:theme` property to set a custom theme:

```xml

<activity
    android:name="com.pspdfkit.example.MyCustomActivity"
    android:label="@string/title_activity_custom"
    android:theme="@style/MyApp.Theme" />

```

To launch `MyCustomActivity`, first create a [`PdfActivityConfiguration`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration.activity/-pdf-activity-configuration/index.html), then create a launching intent using the [`PdfActivityIntentBuilder`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity-intent-builder/index.html), and finally call [`Activity#startActivity`](https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)) with the intent you created:

### KOTLIN

```kotlin

val config = PdfActivityConfiguration.Builder(context).build()
val intent = PdfActivityIntentBuilder.fromUri(context, uri).configuration(config).activity(MyCustomActivity::class.java).build()

// Start the `MyCustomActivity` like any other activity.
context.startActivity(intent)

```

### JAVA

```java

final PdfActivityConfiguration config = new PdfActivityConfiguration.Builder(context).build();
final Intent intent = PdfActivityIntentBuilder.fromUri(context, uri).configuration(config).activity(MyCustomActivity.class).build();

// Start the `MyCustomActivity` like any other activity.
context.startActivity(intent);

```

## Custom activity Layouts

By default, [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) uses the `R.layout.pspdf__pdf_activity` as its layout file. Have a look at that file to see all the views Nutrient uses. You can use the file as a template for your custom layout. To specify the layout, provide its ID to the [`PdfActivityConfiguration.Builder#layout`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration.activity/-pdf-activity-configuration/-builder/layout.html) method. Usually, it also makes sense to subclass the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) so it can make use of the custom layout and the views you may add:

### KOTLIN

```kotlin

val config = PdfActivityConfiguration.Builder(context).layout(R.layout.my_custom_layout).build()

```

### JAVA

```java

final PdfActivityConfiguration config =
    new PdfActivityConfiguration.Builder(context).layout(R.layout.my_custom_layout).build();

```

### Required views

The [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) expects several views to be present in the selected layout file. If any of the following views is missing, Nutrient will throw an [`InvalidLayoutException`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.exceptions/-invalid-layout-exception/index.html):

| View ID                                  | Description                                                                                                                              |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `@id/pspdf__toolbar_coordinator`         | A [`ToolbarCoordinatorLayout`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui.toolbar/-toolbar-coordinator-layout/index.html) for managing and laying out the main toolbar (action bar) and contextual toolbars.                      |
| `@id/pspdf__toolbar_main`                | [`androidx.appcompat.widget.Toolbar`](https://developer.android.com/reference/androidx/appcompat/widget/Toolbar) serves as the activity’s action bar. This has to be wrapped inside the toolbar coordinator view. |
| `@id/pspdf__inspector_coordinator`       | [`PropertyInspectorCoordinatorLayout`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui.inspector/-property-inspector-coordinator-layout/index.html) for managing and laying out the [`PropertyInspector`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui.inspector/-property-inspector/index.html) views.                                  |
| `@id/pspdf__activity_fragment_container` | [`ViewGroup`] or any subclass. The activity will use this to inject the [`PdfFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/index.html).                                               |
| `@id/pspdf__activity_form_editing_bar`   | [`FormEditingBar`] serves as the helper toolbar for filling out interactive forms. This is not required when form editing is disabled.   |

### Optional views

In addition to the mandatory views, the layout may define several optional views. These views may be removed from the original layout. However, if this is done, they need to be deactivated explicitly using the [`PdfActivityConfiguration.Builder`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration.activity/-pdf-activity-configuration/-builder/index.html):

| View ID                                                      | Description                                                                                                                      |
| ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `@id/pspdf__activity_thumbnail_bar`                          | The [`PdfThumbnailBar`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-thumbnail-bar/index.html) for displaying a horizontal list of thumbnails that show the current page.                             |
| `@id/pspdf__activity_page_overlay`                           | A [`TextView`](https://developer.android.com/reference/android/widget/TextView.html) for displaying the current page and total page count (e.g. Page 4 of 22).                                       |
| `@id/pspdf__activity_thumbnail_grid`                         | The [`PdfThumbnailGrid`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-thumbnail-grid/index.html) is a scrollable fullscreen grid of all the pages.                                                     |
| `@id/pspdf__activity_search_view_modular`                    | A [`PdfSearchViewModular`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui.search/-pdf-search-view-modular/index.html) for displaying a search box and a list of search results.                                           |
| `@id/pspdf__activity_outline_view`                           | The [`PdfOutlineView`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-outline-view/index.html), which displays the document outline (table of contents) and a list of all annotations on the document. |
| `@id/pspdf__navigate_back` and `@id/pspdf__navigate_forward` | [`CardView`](https://developer.android.com/reference/android/support/v7/widget/CardView)s that display the buttons for navigating back and forward.                                                        |
| `@id/pspdf__activity_title_overlay`                          | A [`TextView`](https://developer.android.com/reference/android/widget/TextView.html) for displaying the current document’s title.                                                                    |
| `@id/pspdf__activity_tab_bar`                                | The [`PdfTabBar`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui.tabs/-pdf-tab-bar/index.html) for displaying a horizontal list of document tabs.                                                           |
---

## Related pages

- [Building an activity around the PdfFragment](/guides/android/customizing-the-interface/building-an-activity-around-the-pdffragment.md)

