How to run an async task for every x mins in android?

前端 未结 9 1081
长发绾君心
长发绾君心 2020-11-27 12:28

how to run the async task at specific time? (I want to run it every 2 mins)

I tried using post delayed but it\'s not working?

    tvData.postDelayed         


        
9条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 13:24

    you can use TimerTask instead of AsyncTask.

    ex:

    Timer myTimer = new Timer("MyTimer", true);
    myTimer.scheduleAtFixedRate(new MyTask(), ASAP, TWO_MINUTES);
    
    
    private class MyTask extends TimerTask {
    
        public void run(){
          readWebPage();
        }
    
    }
    

提交回复
热议问题