Beispiel #1
0
    @Override
    protected void onPostExecute(AdFetchResult result) {
      if (!isMostCurrentTask()) {
        Log.d("MoPub", "Ad response is stale.");
        releaseResources();
        return;
      }

      // If cleanup() has already been called on the AdView, don't proceed.
      if (mAdView == null || mAdView.isDestroyed()) {
        if (result != null) {
          result.cleanup();
        }
        mAdFetcher.markTaskCompleted(mTaskId);
        releaseResources();
        return;
      }

      if (result == null) {
        if (mException != null) {
          Log.d("MoPub", "Exception caught while loading ad: " + mException);
        }

        mAdView.loadFailUrl();

        /*
         * There are numerous reasons for the ad fetch to fail, but only in the specific
         * case of actual server failure should we exponentially back off.
         *
         * Note: When we call AdView's loadFailUrl() from this block, AdView's mFailUrl
         * will always be null, forcing a scheduled refresh. Here, we place the exponential
         * backoff after AdView's loadFailUrl because we only want to increase refresh times
         * after the first failure refresh timer is scheduled, and not before.
         */
        if (mFetchStatus == FetchStatus.INVALID_SERVER_RESPONSE_BACKOFF) {
          exponentialBackoff();
          mFetchStatus = FetchStatus.NOT_SET;
        }
      } else {
        result.execute();
        result.cleanup();
      }

      mAdFetcher.markTaskCompleted(mTaskId);
      releaseResources();
    }
Beispiel #2
0
    @Override
    protected void onCancelled() {
      if (!isMostCurrentTask()) {
        Log.d("MoPub", "Ad response is stale.");
        releaseResources();
        return;
      }

      Log.d("MoPub", "Ad loading was cancelled.");
      if (mException != null) {
        Log.d("MoPub", "Exception caught while loading ad: " + mException);
      }
      mAdFetcher.markTaskCompleted(mTaskId);
      releaseResources();
    }
Beispiel #3
0
    private DefaultHttpClient getDefaultHttpClient() {
      HttpParams httpParameters = new BasicHttpParams();
      int timeoutMilliseconds = mAdFetcher.getTimeout();

      if (timeoutMilliseconds > 0) {
        // Set timeouts to wait for connection establishment / receiving data.
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutMilliseconds);
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutMilliseconds);
      }

      // Set the buffer size to avoid OutOfMemoryError exceptions on certain HTC devices.
      // http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt
      HttpConnectionParams.setSocketBufferSize(httpParameters, 8192);

      return new DefaultHttpClient(httpParameters);
    }