欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中使用的定時(shí)針(刷新頁面請(qǐng)求服務(wù)器)詳解

 更新時(shí)間:2016年12月23日 14:26:29   投稿:lqh  
這篇文章主要介紹了Android中使用的定時(shí)針(刷新頁面請(qǐng)求服務(wù)器)詳解的相關(guān)資料,需要的朋友可以參考下

我要在程序中用到5秒請(qǐng)求一下數(shù)據(jù)(不建議大家這樣做,我的需求是這樣)

代碼展示:

1.在OnCreate中創(chuàng)建定時(shí)針Timer

//每5秒請(qǐng)求一次服務(wù)器
timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
  @Override
  public void run() {
    Message message=new Message();
    message.what=1;
    handler.sendMessage(message);
  }
}, 1000,5000);

2.在線程中創(chuàng)建Handler

private Handler handler=new Handler(){
  public void handleMessage(Message msg) {
    switch (msg.what) {
      case 1:
        updateTitle();
        break;
      default:
        break;
    }
  };
};

3.創(chuàng)建一個(gè)標(biāo)識(shí)為了做循環(huán)用

private int count=1;

4.在case 1中做需要循環(huán)的需求(我的是5秒請(qǐng)求)

 private void updateTitle() {
    loadHosity();
    count++;
  }

5.完成!

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論