首页 文章

使用计时器从URL重新加载数据

提问于
浏览 394
0

我希望每2分钟后加载一次数据 . 我该怎么做?我已经实现了这个 . 但它不起作用 .

new Handler().postDelayed(new Runnable() {
        public void run() {
            getData();
            Toast.makeText(getContext(),"Loading new data",Toast.LENGTH_SHORT).show();
        }
    }, 10);
public void getData(){
        SharedPreferences preferences = getContext().getSharedPreferences(SP, MODE_PRIVATE);
        final String ip_addr = preferences.getString("ip_addr",null);
        final String port = preferences.getString("port_no",null);
        final ProgressDialog progressDialog = new ProgressDialog(getContext());
        progressDialog.setMessage("Please Wait...");
        progressDialog.show();
        String url = "http://"+ip_addr+":"+port+"/new_crushing_api.php";
//code

1 回答

  • 0
    new CountDownTimer(120000, 1000) {
    
     public void onTick(long millisUntilFinished) {
    
     }
    
     public void onFinish() {
          getData();
            Toast.makeText(getContext(),"Loading new 
     data",Toast.LENGTH_SHORT).show();
     }
    }.start();
    

相关问题