code: public static void setEventListener(final Activity activity,
                                          final KeyboardVisibilityEventListener listener) {
  
          final Unregistrar unregistrar = registerEventListener(activity, listener);
          activity.getApplication()
                  .registerActivityLifecycleCallbacks(new AutoActivityLifecycleCallback(activity) {
                      @Override
                      protected void onTargetActivityDestroyed() {
                          unregistrar.unregister();
                      }
                  });
      }
docs: Set keyboard visibility change event listener.
  This automatically remove registered event listener when the Activity is destroyed
  
  @param activity Activity
  @param listener KeyboardVisibilityEventListener