本文整理汇总了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);
}
示例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();
}
}
示例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();
}
示例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);
}
示例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;
}
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
}
}
示例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);
}
示例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());
}
示例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;
}
}
示例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;
}
示例14: doInBackground
import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected T doInBackground() {
if (throwOperationCanceled) {
throw new OperationCanceledException();
} else {
return result;
}
}
示例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;
}