在后台线程中运行处理程序的消息

编程入门 行业动态 更新时间:2024-10-23 11:16:59
本文介绍了在后台线程中运行处理程序的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要运行一些可运行在后台线程。我想用处理程序,因为它的方便延迟。 我的意思是

I want to run some Runnable in a background thread. I want to use Handler because it's convenient for delays. What I mean is

handler.post(runnable, delay);

其中可运行应背景线程运行。 是否有可能创造这样的处理程序? 是否有背景尺蠖的地方或者我如何创建呢?

Where runnable should be run in background Thread. Is it possible to create such Handler? Is there a "background" Looper somewhere or how can I create it?

P.S。我知道如何与自定义类做扩展线程,但它需要多一点的编码工作不是做它的处理方式。所以,请不要张贴其他的解决方案或类似的东西。

P.S. I know how to do it with a custom class extends Thread but it requires a little more coding effort than doing it the handler way. So please don't post other solutions or something like

handler.post(new Runnable() { @Override public void run() { new Thread() { @Override public void run() { //action } }.start(); } });

我只是游荡,如果处理程序能做到这一点干净的方式。

I just wander if Handler can do it the "clean" way.

推荐答案

您可以通过设置一个活套在后台线程活套。prepare()和 Looper.loop 。

You can set up a Looper in a background thread using Looper.prepare() and Looper.loop.

  • developer.android/reference/android/os/ Looper.html

更多推荐

在后台线程中运行处理程序的消息

本文发布于:2023-10-13 00:08:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   后台   消息   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!