【问题标题】:Does SimpleCursorAdapter run on UI threadSimpleCursorAdapter 是否在 UI 线程上运行
【发布时间】:2013-12-18 10:59:48
【问题描述】:

docs 中提到

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)

不鼓励,因为它会导致在应用程序的 UI 线程上执行游标查询 ..

但是下面的构造函数没有提到

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)

带有第二个构造函数的SimpleCursorAdapter也在UI线程上运行

【问题讨论】:

  • 是的,你必须在 UI 线程上运行它
  • @PiyushGupta 正在询问它是否会在后台线程或 UI 线程上运行
  • 取决于int flags 部分。 stackoverflow.com/questions/11093380/…(使用0,它不会。至少当你的光标窗口没有问题时)
  • @zapl 所以使用 0 标志它不会在 UI 线程上运行,而是在后台线程上运行

标签: java android


【解决方案1】:
all Adapters works on UI Thread in android . if you wants to use from Non UI Thread use this 

runOnUiThread(new Runnable() {

@Override
        public void run() {
            list.setAdapter(adapter);
        }
});
or simply post a runnable to the UI thread:

view.post(new Runnable() {

    @Override
    public void run() {
        list.setAdapter(adapter);
    }

});

【讨论】:

  • 错误...没有。这将是一种在后台线程中创建适配器并将其设置在 ui 线程中的方法。这不会给你带来任何好处。
猜你喜欢
  • 2016-02-10
  • 1970-01-01
  • 2011-09-02
  • 1970-01-01
  • 1970-01-01
  • 2011-08-06
  • 1970-01-01
  • 2012-07-21
  • 1970-01-01
相关资源
最近更新 更多