# Missed Responses

On Android, it’s technically possible for the OS to kill your app while it's in the background before a response is received. If this occurs and the app process is later restarted, you can still receive those missed responses by initializing `TeyaAllInOneSDK` with a `MissedResponseListener`.

To ensure missed responses are delivered, you **must** call `TeyaAllInOneSDK` as early as possible after the app starts, ideally in the `onCreate` method of your `Application` class.

As mentioned in the [Setup section](./setup.md), you can implement the missed responses callback by passing a `MissedResponseListener` to the `TeyaAllInOneSDK` function:

```tabs
    tab:
      title: Kotlin
      content:
        ```kotlin
        val teyaAllInOneSDK = TeyaAllInOneSDK(
            onMissedResponseListener = object : MissedResponseListener {
                override fun onMissedPaymentResponse(
                    eposTransactionId: String,
                    finalState: PaymentStateSubscription.PaymentStateDetails,
                ) {
                    println("MISSED RESPONSE = eposTransactionId=$eposTransactionId, finalState=$finalState")
                }

                override fun onMissedReceiptResponse(
                    gatewayTransactionId: GatewayTransactionId,
                    result: PrintStateDetails,
                ) {
                    println("MISSED RESPONSE = gatewayTransactionId=$gatewayTransactionId, result=$result")
                }

                override fun onMissedCustomReceiptResponse(
                    customReceiptId: String,
                    result: PrintStateDetails,
                ) {
                    println("MISSED RESPONSE = customReceiptId=$customReceiptId, result=$result")
                }

                override fun onMissedRefundResponse(
                    gatewayPaymentId: GatewayPaymentId,
                    result: RefundResultSubscription.ResultDetails,
                ) {
                    println("MISSED RESPONSE = gatewayPaymentId=$gatewayPaymentId, result=$result")
                }

                override fun onMissedUnreferencedRefundResponse(
                    eposTransactionId: String,
                    finalState: PaymentStateSubscription.PaymentStateDetails,
                ) {
                    println("MISSED RESPONSE = eposTransactionId=$eposTransactionId, finalState=$finalState")
                }
            },
            logger = LoggerImpl()
        )
        ```
    tab:
      title: Java
      content:
        ```java
        AllInOneSDK teyaAllInOneSDK = TeyaAllInOneSDK.init(
            new MissedResponseListener() {
                @Override
                public void onMissedPaymentResponse(
                        @NonNull String eposTransactionId,
                        @NonNull PaymentStateSubscription.PaymentStateDetails finalState
                ) {
                    System.out.println("MISSED RESPONSE = eposTransactionId=" + eposTransactionId + ", finalState=" + finalState);
                }

                @Override
                public void onMissedReceiptResponse(
                        @NonNull GatewayTransactionId gatewayTransactionId,
                        @NonNull PrintStateDetails result
                ) {
                    System.out.println("MISSED RESPONSE = gatewayTransactionId=" + gatewayTransactionId + ", result=" + result);
                }

                @Override
                public void onMissedCustomReceiptResponse(
                        @NonNull String customReceiptId,
                        @NonNull PrintStateDetails result
                ) {
                    System.out.println("MISSED RESPONSE = customReceiptId=" + customReceiptId + ", result=" + result);
                }

                @Override
                public void onMissedRefundResponse(
                        @NonNull GatewayPaymentId gatewayPaymentId,
                        @NonNull RefundResultSubscription.ResultDetails result
                ) {
                    System.out.println("MISSED RESPONSE = gatewayPaymentId=" + gatewayPaymentId + ", result=" + result);
                }

                @Override
                public void onMissedUnreferencedRefundResponse(
                        @NonNull String eposTransactionId,
                        @NonNull PaymentStateSubscription.PaymentStateDetails finalState
                ) {
                    System.out.println("MISSED RESPONSE = eposTransactionId=" + eposTransactionId + ", finalState=" + finalState);
                }
            },
            new LoggerImpl(),
            null
        );
        ```
```

The following responses may be missed if the operating system kills the app before they are delivered:

- `onMissedPaymentResponse`: Triggered when a payment response was missed.
- `onMissedReceiptResponse`: Triggered when a receipt printing result was missed.
- `onMissedCustomReceiptResponse`: Triggered when a custom receipt printing result was missed.
- `onMissedRefundResponse`: Triggered when a refund result was missed.
- `onMissedUnreferencedRefundResponse`: Triggered when an unreferenced refund response was missed.
