/**
   * Registers the in-app message manager, which will listen to and display incoming in-app
   * messages. The current Activity is required in order to properly inflate and display the in-app
   * message view.
   *
   * <p>Important note: Every Activity must call registerInAppMessageManager in the onResume
   * lifecycle method, otherwise in-app messages may be lost!
   *
   * @param activity The current Activity.
   */
  public void registerInAppMessageManager(Activity activity) {
    AppboyLogger.d(TAG, "registerInAppMessageManager called");
    // We need the current Activity so that we can inflate or programmatically create the in-app
    // message
    // View for each Activity. We cannot share the View because doing so would create a memory leak.
    mActivity = activity;
    if (mActivity != null && mApplicationContext == null) {
      // Note, because the IAMManager is a singleton and doesn't have any dependencies passed in,
      // we cache the application context here because it's not available (as it normally would be
      // from Appboy initialization).
      mApplicationContext = mActivity.getApplicationContext();
    }

    // We have a special check to see if the host app switched to a different Activity (or recreated
    // the same Activity during an orientation change) so that we can redisplay the in-app message.
    if (mCarryoverInAppMessage != null) {
      AppboyLogger.d(TAG, "Requesting display of carryover in-app message.");
      mCarryoverInAppMessage.setAnimateIn(false);
      displayInAppMessage(mCarryoverInAppMessage, true);
      mCarryoverInAppMessage = null;
    } else if (mUnRegisteredInAppMessage != null) {
      AppboyLogger.d(TAG, "Adding previously unregistered in-app message.");
      addInAppMessage(mUnRegisteredInAppMessage);
      mUnRegisteredInAppMessage = null;
    }

    ensureSubscribedToInAppMessageEvents(mApplicationContext);
  }