我正在使用AsyncTask从OpenWeather API请求,但是响应未返回任何为null的字符串,因此无法处理。通常,当我允许使用StrictMode(禁止NetworkOnMainThreadException)时,它可以在主线程上运行,但是使用AsyncTask却无法获得结果。在logcat的主线程内还会打印太多工作。可能是什么原因?
从 MapsActivity
的 onCreate()方法调用的 getWeather()方法const pages = [
({ style }) => (
<animated.div
style={{
...style,
position: "absolute",
top: "0",
backgroundColor: "red"
}}
>
First page
</animated.div>
),
({ style }) => (
<animated.div
style={{
...style,
position: "absolute",
top: "0",
backgroundColor: "blue"
}}
>
Second page
</animated.div>
)
];
从 getWeather()
调用的 requestWeatherAsync()方法public void getWeather(double lat, double lon) throws IOException, JSONException {
Log.i("lat and lon", String.valueOf((int)lat) + String.valueOf((int)lon));
String url = "http://api.openweathermap.org/data/2.5/weather?lat="
+ (int)lat+"&lon="
+ (int)lon
+"&APPID=apikey";
//new requestWeatherAsync().execute(url);
new requestWeatherAsync().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,url);
if (mPlaceName != "")
Toast.makeText(MapsActivity.this, mPlaceName
+ ", Temp: " + String.valueOf(temperature)
+ DEGREE
+ "C, situation: " + capitalize(description)
, Toast.LENGTH_LONG).show();
}