我開發了一個Android應用程序,它使用Yahoo! Weather API
獲取天氣信息,因爲Yahoo! Weather API
允許每小時只請求服務10 to 20
次。我的應用程序有拖活動時,我來回切換它們之間我的應用程序再次請求氣象服務,並再次我對這個代碼是:代碼一次又一次地請求雅虎天氣服務
@Override
protected void onResume() {
// TODO Auto-generated method stub
String nameOfCity= pref.getString("cityname", cityNameInput.getText().toString());
getWeather(null, nameOfCity);// this the AsyncTask which is used to request Yahoo! Weather service.
cityNameInput.setText(nameOfCity);
super.onResume();
Log.d("My_TAG", "in onResume()");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
editor = pref.edit();
if(cityNameInput.getText().toString().equals("")){
cityNameInput.setText(yahooWeatherInfo.getLocationCity());
}else{
editor.putString("cityname", cityNameInput.getText().toString());
}
editor.commit();
super.onPause();
Log.d("MY_TAG", "in onPause()");
}
現在請告訴我如何限制不再次請求Yahoo! Weather Service
和再次在活動之間切換。
調查您的數據請求Android服務。 – 2013-03-10 06:44:43
@MorrisonChang我該怎麼做,請給我一些提示,如果? – 2013-03-10 06:55:19