code: public boolean waitForActivity(ComponentName name, int retryTime) {
          final int retryPeriod = 250;
          int retryNum = retryTime / retryPeriod;
          for (int i = 0; i < retryNum; i++) {
              if (this.getCurrentActivity().getComponentName().equals(name)) {
                  break;
              }
              if (i == retryNum - 1) {
                  return false;
              }
              this.sleep(retryPeriod);
          }
          return true;
      }
docs: Wait for activity to become active (by component name)
  
  @param name
  @param retryTime