zoukankan      html  css  js  c++  java
  • 定时器的简单实例

    private Timer timer = new Timer();

    timer.schedule(task, 800);

    TimerTask task = new TimerTask() {

    @Override
    public void run() {
    intent = new Intent(LoadUI.this, LoadDataService.class);
    Bundle bundle = new Bundle();
    bundle.putString("city", WeatherUtil.getDefaultCity(LoadUI.this));
    bundle.putBoolean("check", false);
    intent.putExtras(bundle);
    LoadUI.this.startService(LoadUI.this.intent);
    while(true){
    if( ResourceAdapter.getMessageCode() != 0 ){
    handler.sendEmptyMessage(0);
    break;
    }
    }
    }
    };

    Handler handler = new Handler(){

    @Override
    public void handleMessage(Message msg) {
    // TODO Auto-generated method stub
    super.handleMessage(msg);

    if( ResourceAdapter.getMessageCode() == Constant.NET_LINK_ERROR){
    Toast.makeText(LoadUI.this, getString(R.string.net_error),
    Toast.LENGTH_LONG).show();
    }
    if (ResourceAdapter.getMessageCode() == Constant.SUCCESS_FULL) {
    timer.cancel();
    Intent weatherIntent = new Intent();
    weatherIntent.setClass(LoadUI.this, WeatherUI.class);
    LoadUI.this.startActivity(weatherIntent);
    LoadUI.this.stopService(intent);
    LoadUI.this.overridePendingTransition(anim.slide_in_left, anim.slide_out_right);
    LoadUI.this.finish();
    }
    }

    };

  • 相关阅读:
    2019春第一次实验报告
    2019春第二次实验报告
    第十二周编程总结
    第十一周编程总结
    第十周作业
    C语言II博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
    学期总结
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2541565.html
Copyright © 2011-2022 走看看