小编Mah*_*efi的帖子

Looper 线程上的 CoroutineDispatcher

我有一个帮助程序类,用于在数据库领域上执行一些工作。如您所知,我们在使用领域时有一些限制,例如:

  1. Realm 实例不会在非循环线程上自动刷新。
  2. Realm 对象只能在创建它们的线程上访问

我的 Helper 类扩展 CoroutineScope并提供了CoroutineContext我使用的这段代码 Executors.newSingleThreadExecutor().asCoroutineDispatcher()

但我的问题是所有作业都CoroutineScope在非循环线程上运行,所以我如何创建一个ExecutorCoroutineDispatcher在单个循环线程上运行的作业。

很明显我不想使用,Dispatchers.Main因为它应该在我的数据库上完成工作

multithreading android realm kotlin kotlin-coroutines

11
推荐指数
1
解决办法
2464
查看次数

用于滑动图像的 Android 页面指示器

我正在做一个项目。我想用页面指示器显示滑动图像。幻灯片和页面指示器都出现在我的应用程序中,当我滚动图像时,图像成功更改并且工作正常。但我的页面指示器没有改变。当我在 eclipse 中运行代码时,它让我感到困惑,它工作正常,但在 android studio 中却没有。这是我的 PageIndicator:

public class PageIndicator extends ImageView{

private Paint            fillPaint;
private Paint            strokePaint;
private int              count;
private int              indicatorWidth;
private static final int CIRCLE_RADIUS       = 8;
private static final int CIRCLE_SPACE        = 10;
private static final int CIRCLE_STROKE_COLOR = Color.GRAY;
private static final int CIRCLE_FILL_COLOR   = Color.LTGRAY;
private int              screenWidth;
private float            offsetX;
private int              currentPageIndex;
private float            percent;


public PageIndicator(Context context) {
    super(context);
    initialize();
}


public PageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    initialize(); …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager

1
推荐指数
1
解决办法
1690
查看次数