【发布时间】:2015-10-18 01:48:54
【问题描述】:
我会直截了当地说这是一个作业问题。所以我不是在寻找答案,而是在寻找更好的答案。
我们有一个异步任务,它接受三个参数。进度参数(即第二个参数是)是 Runnable 。
@Override
public void onProgressUpdate(Runnable ...runnableCommands) {
// TODO -- you fill in here with the appropriate call to
// the runnableCommands that will cause the progress
// update to be displayed in the UI thread.
}
我可以在 doInBackGround() 方法中使用 publishProgress() 调用此方法。
挑战在于将此可运行对象附加到 UI 线程。我知道 onProgressUpdate() 可以访问 UI 线程,我们可以创建一个处理程序来添加到消息队列。但显然是过分了。
能否指导我找到比创建处理程序更好的方法
【问题讨论】:
-
我从未尝试过,但请尝试 runOnUiThread(Runnable action)。 stackoverflow.com/questions/12316838/…
标签: android concurrency android-asynctask