Multi-activity Integration

Android

It is suggested to maintain a time of 5 seconds or above in between initiate and process. Occasionally this may not be possible within the same Activity. This brings up the use case to call initiate and process from different activities. The SDK takes an Activity and viewGroup as input in the constructor of HyperServices. This activity and view group is used for any UI / context requiring functionality in the SDK. To integrate the SDK across multiple activities the activity and view group must be updated in SDK API. All SDK APIs support overriding the activity and view group.

🚧

Note

ViewGroup and activity passed to the process API is not specific to that process, but modifies the viewGroup for all future process calls.

// If you require the sdk to take up the entire screen,
// please follow the other tab

hyper.initiate((FragmentActivity)activity, (ViewGroup)view, initiatePayload, hyperPaymentsCallback);

hyper.process((FragmentActivity)activity, (ViewGroup)view, processPayload);
// If you require to specify the view group the sdk uses,
// please follow the other tab

hyper.initiate((FragmentActivity)activity, initiatePayload, hyperPaymentsCallback);

hyper.process((FragmentActivity)activity, processPayload);

👍

Note

While integrating across multiple activities, be sure to pass activity in all SDK apis.

Avoiding memory leaks

The SDK holds reference to the activity and view group. While using the SDK across multiple activities, the Android system may destroy older activities. If that was the last activity passed to the SDK, this can create a memory leak.
In order to avoid memory leaks, developers must ensure to call resetActivity function of the HyperServices object, while switching activities. This will ensure that SDK does not hold onto the activity and viewGroup passed to the SDK.

// Should be called in onDestroy.
// Activity being destroyed must be passed as argument
// SDK will use this to determine, whether the current held activity is the one being destroyed
hyper.resetActivity(activity)

❗️

Warning

After calling resetActivity, the next process must pass activity as an argument, else this may result in a crash.

iOS

It is suggested to maintain a time of 5 seconds or above in between initiate and process. Occasionally this may not be possible within the same ViewController. This brings up the use case to call initiate and process from different view controllers. The SDK takes a ViewController as input in initiate API of HyperServices. This view controller will be used as a base view controller for any UI in the SDK. To integrate the SDK across multiple view controller, the base view controller must be updated before calling process API of HyperServices.

To change the baseViewController:

hyperInstance.baseViewController = anotherViewController
self.hyperInstance.baseViewController = anotherViewController;

Similar to the base view controller, the callback block that was passed in initiate can be updated later if the callback needs to handled from different class.

To change the callback block:

hyperInstance.hyperSDKCallback = { [unowned self] response in
    if let data = response {
        let event = data["event"] as? String ?? ""
        if event == "initiate_result" {
            
        } else if event == "process_result" {
            
        }
    }
}
self.hyperInstance.hyperSDKCallback = ^(NSDictionary<NSString *,id> * _Nullable data) {
    if (data && data[@"event"]) {
        if ([event isEqualToString:@"initiate_result"]) {

        } else if ([event isEqualToString:@"process_result"]) {

        }
    }      
};

What’s Next
Did this page help you?