可运行在服务于一个主线程工作 [英] Runnable in service working in a main thread
问题描述
我在机器人编程新。
试图得到一些有用的数据从网络JSON(网络任务)中设置并解析它。
所以我选择这个服务
,为使后台作业。如何正确安装重复任务Handler.postDelayed(可运行,间隔)
不在主
线程?
I'm new in android programming.
Trying to get some useful data set from web json(network task) and parse it.
So i choose for this Service
, for making background job. How do i properly install repeated task with Handler.postDelayed(runnable, interval)
not in the main
thread?
请帮我算出这个?
推荐答案
IntentService
意图在后台工作线程运行。
IntentService
intents run on a background worker thread.
不过,你似乎是发布可运行做网络操作,以处理这很可能是在UI线程上,因为你得到 NetworkOnMainThreadException
。
However, you seem to be posting a runnable doing network operations to a handler which is likely on the UI thread since you're getting NetworkOnMainThreadException
.
这说明了问题。请澄清你想要完成,所以我们可以提出一个更好的办法是什么。
This explains the problem. Please clarify what you're trying to accomplish so we can suggest a better approach.
这篇关于可运行在服务于一个主线程工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!