---
title: "How to invoke the PdfActivity share action programmatically"
canonical_url: "https://www.nutrient.io/guides/android/knowledge-base/invoking-share-action-programmatically/"
md_url: "https://www.nutrient.io/guides/android/knowledge-base/invoking-share-action-programmatically.md"
last_updated: "2026-05-15T19:10:04.908Z"
description: "Learn to programmatically invoke the PdfActivity share action by removing it from the toolbar and calling the appropriate method in your custom activity."
---

If you want to move the share action from the main toolbar of the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html), you can use the following method from your custom activity that extends the `PdfActivity`.

First, remove the share menu item from the main toolbar:

```kt

override fun onCreateOptionsMenu(menu: Menu): Boolean {
    // This populates the menu with main toolbar items.
    super.onCreateOptionsMenu(menu)

    // Store the share menu item for future use.
    shareMenuItem = menu.findItem(PdfActivity.MENU_OPTION_SHARE)

    // Then remove the share item from the main toolbar.
    if (shareMenuItem!= null) {
        menu.removeItem(PdfActivity.MENU_OPTION_SHARE)
    }
}

```

Then, invoke the share action by calling the following:

```kt

if (shareMenuItem!= null) {
    onOptionsItemSelected(shareMenuItem)
}

```
---

## Related pages

- [Allow Clear Text Traffic](/guides/android/knowledge-base/allow-clear-text-traffic.md)
- [Compose Qna](/guides/android/knowledge-base/compose-qna.md)
- [Disabling Annotation Rotation](/guides/android/knowledge-base/disabling-annotation-rotation.md)
- [Custom Print Functionality](/guides/android/knowledge-base/custom-print-functionality.md)
- [Deleting Pages From A Pdf](/guides/android/knowledge-base/deleting-pages-from-a-pdf.md)
- [Easily disable share and print options in Android](/guides/android/knowledge-base/disable-share-documentinfo-print.md)
- [Managing touch scrolling in Compose containers](/guides/android/knowledge-base/document-view-inside-pager-scroll-handling.md)
- [Getting All Digital Signatures](/guides/android/knowledge-base/getting-all-digital-signatures.md)
- [Change page layout dynamically based on orientation](/guides/android/knowledge-base/dynamic-page-layout-when-changing-orientation.md)
- [Getting Signature Location](/guides/android/knowledge-base/getting-signature-location.md)
- [Invoke Search Programmatically](/guides/android/knowledge-base/invoke-search-programmatically.md)
- [Install Failed Insufficient Storage](/guides/android/knowledge-base/install-failed-insufficient-storage.md)
- [Intercepting Touch Events](/guides/android/knowledge-base/intercepting-touch-events.md)
- [Creating invisible digital signatures in Android](/guides/android/knowledge-base/invisible-signature.md)
- [Making Form Elements Read Only](/guides/android/knowledge-base/making-form-elements-read-only.md)
- [Override Hyperlink Behavior](/guides/android/knowledge-base/override-hyperlink-behavior.md)
- [Runtime Permissions Cordova](/guides/android/knowledge-base/runtime-permissions-cordova.md)
- [Remove Tool Variant From Toolbar](/guides/android/knowledge-base/remove-tool-variant-from-toolbar.md)
- [Customize the overflow button color in Android](/guides/android/knowledge-base/styling-overflow-button.md)
- [Save signed PDFs directly to a remote server on Android](/guides/android/knowledge-base/save-signed-pdfs-to-remote-server.md)
- [Using Pspdfkit With Dynamic Feature Modules](/guides/android/knowledge-base/using-pspdfkit-with-dynamic-feature-modules.md)

