예제 #1
0
  @Override
  /**
   * When this activity pauses, this method sets the current activity to null, fires a javascript
   * 'pause' event, and if the activity is finishing, remove all dialogs associated with it.
   */
  protected void onPause() {
    inForeground = false;
    super.onPause();
    isResumed = false;

    Log.d(TAG, "Activity " + this + " onPause", Log.DEBUG_MODE);

    TiApplication tiApp = getTiApp();
    if (tiApp.isRestartPending()) {
      releaseDialogs(true);
      if (!isFinishing()) {
        finish();
      }
      return;
    }

    if (!windowStack.empty()) {
      windowStack.peek().onWindowFocusChange(false);
    }

    TiApplication.updateActivityTransitionState(true);
    tiApp.setCurrentActivity(this, null);
    TiUIHelper.showSoftKeyboard(getWindow().getDecorView(), false);

    if (this.isFinishing()) {
      releaseDialogs(true);
    } else {
      // release non-persistent dialogs when activity hides
      releaseDialogs(false);
    }

    if (activityProxy != null) {
      activityProxy.fireSyncEvent(TiC.EVENT_PAUSE, null);
    }

    synchronized (lifecycleListeners.synchronizedList()) {
      for (OnLifecycleEvent listener : lifecycleListeners.nonNull()) {
        try {
          TiLifecycle.fireLifecycleEvent(this, listener, TiLifecycle.LIFECYCLE_ON_PAUSE);

        } catch (Throwable t) {
          Log.e(TAG, "Error dispatching lifecycle event: " + t.getMessage(), t);
        }
      }
    }

    // Checkpoint for ti.end event
    if (tiApp != null) {
      tiApp.postAnalyticsEvent(TiAnalyticsEventFactory.createAppEndEvent());
    }
  }
예제 #2
0
  @Override
  /**
   * When the activity resumes, this method updates the current activity to this and fires a
   * javascript 'resume' event.
   */
  protected void onResume() {
    inForeground = true;
    super.onResume();
    if (isFinishing()) {
      return;
    }

    Log.d(TAG, "Activity " + this + " onResume", Log.DEBUG_MODE);

    TiApplication tiApp = getTiApp();
    if (tiApp.isRestartPending()) {
      if (!isFinishing()) {
        finish();
      }
      return;
    }

    if (!windowStack.empty()) {
      windowStack.peek().onWindowFocusChange(true);
    }

    tiApp.setCurrentActivity(this, this);
    TiApplication.updateActivityTransitionState(false);

    if (activityProxy != null) {
      // Fire the sync event with a timeout, so the main thread won't be blocked too long to get an
      // ANR. (TIMOB-13253)
      activityProxy.fireSyncEvent(TiC.EVENT_RESUME, null, 4000);
    }

    synchronized (lifecycleListeners.synchronizedList()) {
      for (OnLifecycleEvent listener : lifecycleListeners.nonNull()) {
        try {
          TiLifecycle.fireLifecycleEvent(this, listener, TiLifecycle.LIFECYCLE_ON_RESUME);

        } catch (Throwable t) {
          Log.e(TAG, "Error dispatching lifecycle event: " + t.getMessage(), t);
        }
      }
    }

    isResumed = true;

    // Checkpoint for ti.start event
    String deployType = tiApp.getAppProperties().getString("ti.deploytype", "unknown");
    tiApp.postAnalyticsEvent(TiAnalyticsEventFactory.createAppStartEvent(tiApp, deployType));
  }