一个android Timer,为什么只执行了一次
public void getPaisong() { final Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1: { // 初始化搜索模块,注册事件监听 mSearch = new MKSearch(); mSearch.init(app.mBMapMan, new MyMKSearchListener()); jiexi(); cou++; Toast.makeText( BMapApiDemoApp.mDemoApp.getApplicationContext(), "执行了"+cou+"一次!", Toast.LENGTH_LONG).show(); } break; } super.handleMessage(msg); } }; TimerTask task = new TimerTask() { public void run() { Message message = new Message(); message.what = 1; handler.sendMessage(message); } }; timer = new Timer(true); timer.schedule(task, 5000); // 延时1000ms后执行,1000ms执行一次 // timer.cancel(); //退出计时器 }