• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OperationCanceledException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: initCancellationSignal

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
private CancellationSignal initCancellationSignal() {
  synchronized (this) {
    if (isLoadInBackgroundCanceled()) {
      throw new OperationCanceledException();
    }
    mCancellationSignal = new CancellationSignal();
    return mCancellationSignal;
  }
}
 
开发者ID:futuresimple,项目名称:android-db-commons,代码行数:10,代码来源:ComposedCursorLoader.java


示例17: onStart

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected void onStart(final Receiver receiver) {
    task = new AsyncTask<Void, Void, Cursor>() {
        @Override
        protected Cursor doInBackground(Void... params) {
            synchronized (this) {
                if (isCancelled()) {
                    return null;
                }
                cancellationSignal = new CancellationSignal();
            }

            try {
                Cursor cursor = ContentResolverCompat.query(resolver,
                        uri, projection, selection, selectionArgs, sortOrder, cancellationSignal);
                if (cursor != null) {
                    try {
                        // Ensure the cursor window is filled.
                        cursor.getCount();
                        cursor.registerContentObserver(observer);
                    } catch (RuntimeException e) {
                        cursor.close();
                        throw e;
                    }
                }
                return cursor;
            } catch (OperationCanceledException e) {
                // The query was canceled, this result won't be delivered anyway.
                return null;
            } finally {
                synchronized (this) {
                    cancellationSignal = null;
                }
            }
        }

        @Override
        protected void onPostExecute(Cursor cursor) {
            if (!isRunning()) {
                if (cursor != null) {
                    cursor.close();
                }
                return;
            }

            Cursor oldCursor = CursorLoader.this.cursor;
            CursorLoader.this.cursor = cursor;

            receiver.result(cursor);

            if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
                oldCursor.close();
            }
        }
    };
    task.execute();
}
 
开发者ID:evant,项目名称:loadie,代码行数:58,代码来源:CursorLoader.java


示例18: onStart

import android.support.v4.os.OperationCanceledException; //导入依赖的package包/类
@Override
protected void onStart(final Receiver receiver) {
    task = new AsyncTask<Void, Void, Cursor>() {
        @Override
        protected Cursor doInBackground(Void... params) {
            synchronized (this) {
                if (isCancelled()) {
                    return null;
                }
                cancellationSignal = new CancellationSignal();
            }

            try {
                Cursor cursor = ContentResolverCompat.query(resolver,
                        uri, projection, selection, selectionArgs, sortOrder, cancellationSignal);
                if (cursor != null) {
                    try {
                        // Ensure the cursor window is filled.
                        cursor.getCount();
                        cursor.registerContentObserver(observer);
                    } catch (RuntimeException e) {
                        cursor.close();
                        throw e;
                    }
                }
                return cursor;
            } catch (OperationCanceledException e) {
                // The query was canceled, this result won't be delivered anyway.
                return null;
            } finally {
                synchronized (this) {
                    cancellationSignal = null;
                }
            }
        }

        @Override
        protected void onPostExecute(Cursor cursor) {
            if (!isRunning()) {
                if (cursor != null) {
                    cursor.close();
                }
                return;
            }

            Cursor oldCursor = CursorLoader.this.cursor;
            CursorLoader.this.cursor = cursor;

            receiver.deliverResult(cursor);

            if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
                oldCursor.close();
            }
        }
    };
    task.execute();
}
 
开发者ID:evant,项目名称:retain-state,代码行数:58,代码来源:CursorLoader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OnLocationUpdatedListener类代码示例发布时间:2022-05-22
下一篇:
Java JPAExpressions类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap