---
page_source: https://juspay.io/in/docs/ec-headless/react-native/base-sdk-integration/life-cycle-events
page_title: 7. Life Cycle Events
---


## 7. Life Cycle Events



Express Checkout SDK runs in a fragment. Hence, to handle certain events based upon activity life cycle, client will need to forward those events to Express Checkout SDK.

These events are crucial for seamless functioning of features like OTP reading, App Switches (UPI Intent), Hardware backpress.

Following are the Life cycle events which SDK needs


### Step 7.1. onBackPressed


In order to handle hardware backpress done by user, you have to call `onBackPressed()` on HyperServices Instance in the onBackPressed function of your Checkout Activity.

onBackPressed function returns a boolean. When this return value is true hardware backpressed is consumed by Juspay SDK, if its false you need to handle backpress




### Step 7.2. (Conditional) onActivityResult


In order to handle results of App Switches in cases like UPI Intent transactions, you need to call `super.onActivityResult()` if available, if not you can make same function call on HyperServices Instance.

> **Note**
> This is a conditional step, and is only supposed to be implemented if you are **overriding** onActivityResult.






### Step 7.3. (Conditional) onRequestPermissionsResult


In order to handle results of Permission Request results for cases like OTP Reading, you need to call `super.onRequestPermissionsResult()` in your onRequestPermissionsResult lifeCycle hook, if available, if not you can make same function call on HyperServices Instance.

> **Note**
> This is a conditional step, and is only supposed to be implemented if you are **overriding**  onRequestPermissionsResult





## Sample Code Snippets:
### Life Cycle Events:

#### onBackPressed
 Code Snippet:

```onbackpressed

//block:start:onBackPressed
@Override
public void onBackPressed() {
    boolean backPressHandled = hyperServices.onBackPressed();
    if(!backPressHandled) {
        super.onBackPressed();
    }
}
//block:end:onBackPressed
```

#### onActivityResult
 Code Snippet:

```onactivityresult

 - onActivityResult
    - Handling onActivityResult hook and passing data to HyperServices Instance, to handle App Switch
    @Override
    public void onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        // block:start:onActivityResult

        // If super.onActivityResult is available use following:
        // super.onActivityResult(requestCode, resultCode, data);

        // In case super.onActivityResult is NOT available please use following:
        // if (data != null) {
        //    hyperServices.onActivityResult(requestCode, resultCode, data);
        // }

        // block:end:onActivityResult
```

#### onRequestPermissionsResult
 Code Snippet:

```onrequestpermissionsresult

 - onRequestPermissionsResult
    - Handling onRequestPermissionsResult hook and passing data to HyperServices Instance, to OTP reading permissions
    @Override
    public void onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        // block:start:onRequestPermissionsResult

        //  If super.onRequestPermissionsResult is available use following:
        // super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // In case super.onActivityResult is NOT available please use following:
        // hyperServices.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // block:end:onRequestPermissionsResult
```

