Handler和Timer怎么结合使用啊? 我想用这两个结合使用,实现一个延迟的效果。。但不知道具体应该怎么。。有没有高手给个思路或者给给个简单的小例子。谢谢啊!
------解决方案--------------------
Handler自带有延时发送的函数sendMessageDelayed(msg, delayMillis),延时delayMillis毫秒会收到msg消息
------解决方案--------------------
- Java code
public class Delayed extends Activity { Timer timer = new Timer(); Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case 1: setTitle("hear me?"); break; } super.handleMessage(msg); } }; TimerTask task = new TimerTask(){ public void run() { Message message = new Message(); message.what = 1; handler.sendMessage(message); } }; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); timer.schedule(task, 10000); } }