can any one please tell me how to call a webservice repeatedly for every period of time.(for exapmple i want to call webservice for every 5min). In my app I have a spinner that allows user to select after how many minutes the webservice has to be refreshed. here is the code i wrote using countdown timer.
我在此写道,如果选择了“不复健”的钥匙,应当停止时间。 一旦选择了除第一项目以外的任何项目,然后如果我选择第一个项目(即:不复读),时间就不再停止。 在此,我呼吁采用定点方法,一再呼吁。
private String[] refreshtimes = { "do not refresh","1 minute Refresh", "5minute Refresh",
"15 minute Refresh", "30 minute Refresh", "45 min Refresh",
"60 minute Refresh" };
sp_refresh = (Spinner) findViewById(R.id.refresh);
ArrayAdapter<String> spdptr = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_spinner_item,
refreshtimes);
sp_refresh.setAdapter(spdptr);
sp_refresh.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
if(position!=0 )
{
int time=0;
switch (position) {
case 1:
time=1;
break;
case 2:
time=5;
break;
case 3:
time=15;
break;
case 4:
time=30;
break;
case 5:
time=45;
break;
case 6:
time=60;
break;
default:
break;
}
counter = new MyCount(time*1000,1000);
counter.start();
}
else if(position==0&&counter!=null)
{
counter.cancel();
counter=null;
Toast.makeText(getApplicationContext(), "u r in elsee",10000).show();
}
}
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
// tv.setText("done!");
callservice();
Toast.makeText(getApplicationContext(), "hi..",10000).show();
//onCreate(savedInstanceState);
this.start();
}
@Override
public void onTick(long millisUntilFinished) {
// tv.setText("”Left: " + millisUntilFinished/1000);
Toast.makeText(getApplicationContext(), "Left: " + millisUntilFinished/1000,10000).show();
}
}