
我一直在阅读关于此事的Android文档(AsyncTask,Thread)和vogella tutorial,但我还有疑问.
例如,我想从AndroID应用程序向服务器发送消息.我希望这个过程能够做出回应.我该怎么用?
我见过他们创建一个新的Thread for not block UI的例子,但是这样我们没有进程的进度,你也必须在Thread中处理响应因为run()方法没有返回任何东西.
AsyncTask似乎比Thread更好,但我不知道使用AsyncTask而不是Thread的后果是什么.
解决方法:
请阅读此博客
http://crazyaboutandroid.blogspot.in/2011/12/difference-between-android.html
和细节是:
AndroID Service,Thread,IntentService和AsyncTask之间的区别
什么时候用?
服务
Task with no UI, but shouldn't be too long. Use threads within service for long tasks.线
- Long task in general.- For tasks in parallel use Multiple threads (Traditional mechanisms)的AsyncTask
- Small task having to communicate with main thread.- For tasks in parallel use multiple instances OR Executor 总结 以上是内存溢出为你收集整理的android – AsyncTask和Thread之间的真正区别全部内容,希望文章能够帮你解决android – AsyncTask和Thread之间的真正区别所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)