gpt4 book ai didi

android - onLoadFinished() 是异步的(后台线程)吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:55 24 4
gpt4 key购买 nike

我目前正在考虑使用加载器管理器在抽屉布局中填充我的可扩展 ListView 。如果回调函数 onLoadFinished() 在 UI 线程或后台线程上运行,我在文档中找不到任何地方。它在后台线程上吗?

最佳答案

如果您从 UI 线程调用了 init(),则肯定会在 UI 线程上调用 onLoadFinished()。如果您从后台调用例如 AsyncTaskLoader,将通知结果的线程将是您初始化加载器的线程。

...但是您仍然可以执行以下操作:

@Override
public void onLoadFinished(Loader<String> arg0, String arg1) {
Runnable populate = new Runnable(){

@Override
public void run() {
//your code
}

};
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
//on Ui thread
populate.run();
}else{
this.runOnUiThread(populate); //or use handler to run the runnable
}

}

:)

关于android - onLoadFinished() 是异步的(后台线程)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18326313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com