コード例 #1
0
  /**
   * Handle hardware (re)configurations, such as rotating the display.
   *
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  public void handleConfiguration(Class<OpsType> opsType, Interface instance)
      throws InstantiationException, IllegalAccessException {

    // If this method returns true it's the first time the
    // Activity has been created.
    if (mRetainedFragmentManager.firstTimeIn()) {
      Log.d(TAG, "First time onCreate() call");

      // Initialize the GenericActivity fields.
      initialize(opsType, instance);
    } else {
      // The RetainedFragmentManager was previously initialized,
      // which means that a runtime configuration change
      // occured.
      Log.d(TAG, "Second or subsequent onCreate() call");

      // Try to obtain the OpsType instance from the
      // RetainedFragmentManager.
      mOpsInstance = mRetainedFragmentManager.get(opsType.getSimpleName());

      // This check shouldn't be necessary under normal
      // circumstances, but it's better to lose state than to
      // crash!
      if (mOpsInstance == null)
        // Initialize the GenericActivity fields.
        initialize(opsType, instance);
      else
        // Inform it that the runtime configuration change has
        // completed.
        mOpsInstance.onConfiguration(instance, false);
    }
  }
コード例 #2
0
  /**
   * Initialize the GenericActivity fields.
   *
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  private void initialize(Class<OpsType> opsType, Interface instance)
      throws InstantiationException, IllegalAccessException {
    // Create the OpsType object.
    mOpsInstance = opsType.newInstance();

    // Put the OpsInstance into the RetainedFragmentManager under
    // the simple name.
    mRetainedFragmentManager.put(opsType.getSimpleName(), mOpsInstance);

    // Perform the first initialization.
    mOpsInstance.onConfiguration(instance, true);
  }