Java android-在2秒内从后台动态调用url
我在android应用程序中有一个url,它从异步任务中获取数据,如下所示Java android-在2秒内从后台动态调用url,java,android,Java,Android,我在android应用程序中有一个url,它从异步任务中获取数据,如下所示 new AsyncParam().execute("http://10.0.2.2:88/API/web/app_dev.php/get/1/7"); 请问如何确保每1秒动态调用一次上述url我是否必须创建一个使用此url的方法。将其粘贴到oncreate方法中会引发ExceptionsWhat exception获取的变量处理程序是从内部类中访问的,需要声明finalhandler.postDelayed(runn
new AsyncParam().execute("http://10.0.2.2:88/API/web/app_dev.php/get/1/7");
请问如何确保每1秒动态调用一次上述url我是否必须创建一个使用此url的方法。将其粘贴到oncreate方法中会引发ExceptionsWhat exception获取的变量处理程序是从内部类中访问的,需要声明finalhandler.postDelayed(runnable,1000);前两行处理程序=new Handler();可运行的可运行的;写在你的oncreate上面。你会没事的
Use this:
//Declare globally
Handler handler = new Handler();
Runnable runnable;
//then whereever you want to call your url
runnable = new Runnable() {
@Override
public void run() {
new AsyncParam().execute("http://10.0.2.2:88/API/web/app_dev.php/get/1/7");
//this will call your url after every one sec
handler.postDelayed(runnable,1000);
}
};
//in place of 1000 provide initial delay you can give 0 also if you want to call immediately
handler.postDelayed(runnable,1000);