当前位置: 首页>>代码示例>>Java>>正文


Java OperationCanceledException类代码示例

本文整理汇总了Java中android.support.v4.os.OperationCanceledException的典型用法代码示例。如果您正苦于以下问题:Java OperationCanceledException类的具体用法?Java OperationCanceledException怎么用?Java OperationCanceledException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OperationCanceledException类属于android.support.v4.os包,在下文中一共展示了OperationCanceledException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onStart

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected final void onStart(final Receiver receiver) {
    task = new AsyncTask<Void, Void, T>() {
        @Override
        protected T doInBackground(Void... params) {
            try {
                return AsyncTaskLoader.this.doInBackground();
            } catch (OperationCanceledException e) {
                if (!isRunning()) {
                    return null;
                } else {
                    // Thrown when not actually canceled, just propagate exception.
                    throw e;
                }
            }
        }

        @Override
        protected void onPostExecute(T value) {
            receiver.deliverResult(value);
            receiver.complete();
        }
    };
    task.executeOnExecutor(executor);
}
 
开发者ID:evant,项目名称:retain-state,代码行数:26,代码来源:AsyncTaskLoader.java

示例2: loadInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
public T loadInBackground() {
  Cursor cursor = null;
  try {
    CancellationSignal cancellationSignal = initCancellationSignal();
    cursor = loadCursorInBackground();
    cancellationSignal.throwIfCanceled();
    final T result = mCursorTransformation.apply(cursor, cancellationSignal);
    Preconditions.checkNotNull(result, "Function passed to this loader should never return null.");

    synchronized (pendingLoadResults) {
      pendingLoadResults.add(new Pair<>(result, cursor));
    }

    return result;
  } catch (OperationCanceledException ex) {
    releaseCursor(cursor);
    throw ex;
  } catch (Throwable t) {
    throw new RuntimeException("Error occurred when running loader: " + this, t);
  } finally {
    destroyCancellationSignal();
  }
}
 
开发者ID:futuresimple,项目名称:android-db-commons,代码行数:25,代码来源:ComposedCursorLoader.java

示例3: executePendingTask

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Implementation
public void executePendingTask() {
  new AsyncTask<Void, Void, T>() {

    @Override
    protected T doInBackground(Void... voids) {
      try {
        return realLoader.loadInBackground();
      } catch (OperationCanceledException ex) {
        return null;
      }
    }

    @Override
    protected void onPostExecute(T result) {
      //Deliver result only if doInBackground was not cancelled
      if (result != null) {
        realLoader.dispatchOnLoadComplete(realLoader.mTask, result);
      } else {
        realLoader.dispatchOnCancelled(realLoader.mCancellingTask, null);
      }
    }
  }.execute();
}
 
开发者ID:futuresimple,项目名称:android-db-commons,代码行数:25,代码来源:ShadowAsyncTaskLoader.java

示例4: query

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
public Cursor query(ContentResolver resolver, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) {
    Object cancellationSignalObject;
    if (cancellationSignal != null) {
        try {
            cancellationSignalObject = cancellationSignal.getCancellationSignalObject();
        } catch (Exception e) {
            if (ContentResolverCompatJellybean.isFrameworkOperationCanceledException(e)) {
                throw new OperationCanceledException();
            }
            throw e;
        }
    }
    cancellationSignalObject = null;
    return ContentResolverCompatJellybean.query(resolver, uri, projection, selection, selectionArgs, sortOrder, cancellationSignalObject);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:16,代码来源:ContentResolverCompat.java

示例5: loadInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
public Cursor loadInBackground() {
    Cursor cursor;
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        this.mCancellationSignal = new CancellationSignal();
    }
    try {
        cursor = ContentResolverCompat.query(getContext().getContentResolver(), this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder, this.mCancellationSignal);
        if (cursor != null) {
            cursor.getCount();
            cursor.registerContentObserver(this.mObserver);
        }
        synchronized (this) {
            this.mCancellationSignal = null;
        }
        return cursor;
    } catch (RuntimeException ex) {
        cursor.close();
        throw ex;
    } catch (Throwable th) {
        synchronized (this) {
            this.mCancellationSignal = null;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:28,代码来源:CursorLoader.java

示例6: doInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
protected D doInBackground(Void... params) {
    try {
        return AsyncTaskLoader.this.onLoadInBackground();
    } catch (OperationCanceledException ex) {
        if (isCancelled()) {
            return null;
        }
        throw ex;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:11,代码来源:AsyncTaskLoader.java

示例7: solveHanoi

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
public static void solveHanoi(int totalDisk, Callback callback, CancellationSignal cancel) {
    try {
        Brain brain = new Brain(callback, cancel);
        brain.moveHanoiTower(totalDisk, totalDisk - 1, 0, 2, 1);

        callback.onFinished();
    } catch (OperationCanceledException e) {
        callback.onCanceled();
    }
}
 
开发者ID:chengpo,项目名称:hanoi-animation,代码行数:11,代码来源:Brain.java

示例8: moveHanoiTower

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
private void moveHanoiTower(int totalDisk, int maxDiskId, int from, int to, int spare)
        throws OperationCanceledException {
    cancel.throwIfCanceled();

    if (totalDisk == 1) {
        callback.onMoveDisk(maxDiskId, from, to);
    } else {
        moveHanoiTower(totalDisk - 1, maxDiskId - 1, from, spare, to);
        callback.onMoveDisk(maxDiskId, from, to);
        moveHanoiTower(totalDisk - 1, maxDiskId - 1, spare, to, from);
    }
}
 
开发者ID:chengpo,项目名称:hanoi-animation,代码行数:13,代码来源:Brain.java

示例9: loadInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
public Cursor loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        this.mCancellationSignal = new CancellationSignal();
    }
    Cursor cursor;
    try {
        cursor = ContentResolverCompat.query(getContext().getContentResolver(), this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder, this.mCancellationSignal);
        if (cursor != null) {
            cursor.getCount();
            cursor.registerContentObserver(this.mObserver);
        }
        synchronized (this) {
            this.mCancellationSignal = null;
        }
        return cursor;
    } catch (RuntimeException ex) {
        cursor.close();
        throw ex;
    } catch (Throwable th) {
        synchronized (this) {
            this.mCancellationSignal = null;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:CursorLoader.java

示例10: onStart

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected final void onStart(final Receiver receiver) {
    task = new AsyncTask<Void, T, Pair<T, Throwable>>() {
        @Override
        protected Pair<T, Throwable> doInBackground(Void... params) {
            try {
                return Pair.create(AsyncTaskLoader.this.doInBackground(), null);
            } catch (OperationCanceledException e) {
                if (!isRunning()) {
                    return null;
                } else {
                    // Thrown when not actually canceled, just propagate exception.
                    throw e;
                }
            } catch (Exception e) {
                return Pair.<T, Throwable>create(null, e);
            }
        }

        @Override
        protected void onPostExecute(Pair<T, Throwable> result) {
            if (result.second == null) {
                receiver.success(result.first);
            } else {
                receiver.error(result.second);
            }
        }
    };
    task.executeOnExecutor(executor);
}
 
开发者ID:evant,项目名称:loadie,代码行数:31,代码来源:AsyncTaskLoader.java

示例11: canceledExceptionPropagates

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Test
public void canceledExceptionPropagates() {
    background.pause();

    loader.start();
    loader.throwCanceledException();

    background.unPause();

    assertNotNull(backgroundExecutor.exception);
    assertEquals(OperationCanceledException.class, backgroundExecutor.exception.getCause().getClass());
}
 
开发者ID:evant,项目名称:loadie,代码行数:13,代码来源:AsyncTaskLoaderTest.java

示例12: doInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected T doInBackground() {
    if (throwException) {
        throw new RuntimeException();
    } else if (throwOperationCanceled) {
        throw new OperationCanceledException();
    } else {
        return result;
    }
}
 
开发者ID:evant,项目名称:loadie,代码行数:11,代码来源:TestAsyncTaskLoader.java

示例13: catch

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
private D doInBackground$532ebdd5()
{
  try
  {
    Object localObject = AsyncTaskLoader.this.loadInBackground();
    return localObject;
  }
  catch (OperationCanceledException localOperationCanceledException)
  {
    if (!this.mFuture.isCancelled()) {
      throw localOperationCanceledException;
    }
  }
  return null;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:16,代码来源:AsyncTaskLoader.java

示例14: doInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected T doInBackground() {
    if (throwOperationCanceled) {
        throw new OperationCanceledException();
    } else {
        return result;
    }
}
 
开发者ID:evant,项目名称:retain-state,代码行数:9,代码来源:TestAsyncTaskLoader.java

示例15: loadInBackground

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
public D loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }
    Cursor cursor = null;
    try {
        cursor = mCursorTransform.performQuery(this, mCancellationSignal);
        if (cursor != null) {
            try {
                // Ensure the cursor window is filled.
                cursor.getCount();
                cursor.registerContentObserver(mObserver);
            } catch (RuntimeException ex) {
                cursor.close();
                throw ex;
            }
        }
    } finally {
        synchronized (this) {
            mCancellationSignal = null;
        }
    }

    if (cursor != null) {
        try {
            return mCursorTransform.cursorToModel(this, cursor);
        } finally {
            cursor.close();
        }
    }
    return null;
}
 
开发者ID:google,项目名称:iosched,代码行数:37,代码来源:CursorModelLoader.java


注:本文中的android.support.v4.os.OperationCanceledException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。