刚刚装了Together for VS.NET

感觉还可以,可以导C#代码
比XDE好,XDE不知道怎么导代码

转载于:https://www.cnblogs.com/evernory/archive/2004/07/14/24266.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
In Android, Looper and Handler work together to execute tasks on a separate thread, also known as a background thread. A Looper is an object that allows a thread to handle incoming messages or tasks. It runs in an infinite loop, waiting for new tasks to arrive. When a new task arrives, the Looper dispatches it to the appropriate Handler for processing. A Handler is an object that receives tasks from the Looper and processes them. It is associated with a specific thread, and when a task is sent to a Handler, it is added to a message queue. The Handler processes the tasks one by one, in the order they were added to the queue. Together, the Looper and Handler allow us to perform time-consuming tasks on a separate thread, without blocking the main thread. The main thread is responsible for handling UI events, and if it is blocked by a long-running task, the user interface will become unresponsive. By using Looper and Handler, we can keep the main thread free to handle UI events while executing time-consuming tasks on a separate thread. Here is an example of how Looper and Handler work together: ``` public class MyThread extends Thread { public Handler handler; @Override public void run() { Looper.prepare(); handler = new Handler() { @Override public void handleMessage(Message msg) { // Process the task here } }; Looper.loop(); } } ``` In this example, we create a new thread called `MyThread`. In the `run()` method, we create a new `Looper` and call `prepare()` to initialize it. We then create a new `Handler` and associate it with the thread. Finally, we call `Looper.loop()` to start the infinite loop and wait for tasks to arrive. To send a task to `MyThread`, we can use the `handler` object: ``` MyThread myThread = new MyThread(); myThread.start(); Message msg = myThread.handler.obtainMessage(); msg.obj = "Hello"; myThread.handler.sendMessage(msg); ``` In this example, we create a new message and set its `obj` property to `"Hello"`. We then send the message to `MyThread` using its `handler` object. When the message arrives, the `handleMessage()` method of the `Handler` will be called, and we can process the task there.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值