# Show a survey in an Android app

Trigger a survey from an activity after a purchase, a support interaction or another moment you choose. Shopoll opens a bottom sheet and uses the same questions, appearance and branching as the web survey.

## Run the example

1. Publish a survey. Leave automatic website selection off if you only want to trigger it from your app.
2. Open **Installation → Android SDK**, select the survey and download the SDK and example. The Kotlin snippet contains the public workspace and survey IDs.
3. Unzip the download, open the Shopoll folder in Android Studio and run the **example** module. Use Android 7.0 (API 24) or later with an up-to-date Android System WebView.
4. Enter the Shopoll app address and both IDs from the setup snippet, then choose **Preview survey**.

Choose **Open live survey** to submit a real response. Preview opens fresh. Test answers appear under **Results → Explore → Preview responses** and use no response allowance.

## Add the SDK to your app

Copy `shopoll-android.aar` into your app module’s `libs` folder and add `implementation(files("libs/shopoll-android.aar"))` to its Gradle dependencies. Sync the project. The SDK works from Java and Kotlin and includes the internet permission.

Keep a client for the active account. From a visible activity, use the Kotlin code in **Installation**. Its final constructor argument controls preview mode. Set it to `false` for live surveys.

## Identify a participant

Call `shopoll.identify(id, mapOf("plan" to "plus"))` when your customer signs in and `shopoll.logout()` on sign-out. Use `shopoll.setMetadata(mapOf("screen" to "order-history"))` for details about the survey trigger. The SDK adds the platform, source, SDK version and app version. Anonymous surveys omit custom identity and metadata.

Live answers are saved as a participant advances. A partial survey reopens on the original published revision. A previously completed response keeps the sheet closed. By default, progress is specific to the installation and signed-in identity. To share progress across installations, supply the same private random UUID from your authenticated backend as the third argument to `identify`. Keep this resume key out of links and logs.

## Handle callbacks

Call `setListener` with a `Shopoll.Listener` and implement the callbacks your app needs. `onLoad` runs when the sheet opens. `onComplete` and `onClose` receive answer lists with question IDs, labels, values and write-ins. Closing after completion can invoke both callbacks. `onError` receives the reason a survey could not open. Use `shopoll.close()` to dismiss the sheet from your app.
