每次在调用连续时出现outofmemory异常并在RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext())时发生错误;当连续调用Volley时出现outofmemoryException
每隔5秒钟调用一次这样的方法。
handlerGetJockyLatLong = new Handler();
runnableJockyLatLong = new Runnable() {
@Override
public void run() {
handlerGetJockyLatLong.postDelayed(runnableJockyLatLong, 10000);
getJockyLatLongFromBackEnd();
}
};
handlerGetJockyLatLong.postDelayed(runnableJockyLatLong, 10000);
方法是:
private void getJockyLatLongFromBackEnd() {
final String getJockyID_URL = getProfileInformationURL(getUserAccessToken(UserSideTrackingPage.this), UserID);
Log.e("getJockyID_URL", getJockyID_URL);
StringRequest request = new StringRequest(Request.Method.GET, getJockyID_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (response != null && !response.startsWith("<HTML>")) {
Log.e("getJocky_Url_Responce", response);
//progressDialog.dismiss();
try {
JSONObject jsonObject = new JSONObject(response);
JSONObject jsonObbjectError = jsonObject.getJSONObject("error");
String errorCode = jsonObbjectError.getString("code");
String errorMessage = jsonObbjectError.getString("message");
if (errorCode.equals("0")) {
if (jsonObject.has("data")) {
JSONObject jsonObjectData = jsonObject.getJSONObject("data");
Double latitude = Double.valueOf(jsonObjectData.getString("latitude"));
Double longitude = Double.valueOf(jsonObjectData.getString("longitude"));
globalGoogleMap.clear();
currentLocationMarker = CommonUtils.createMultipleMarkers(globalGoogleMap, latitude, longitude, "Jocky Location", R.drawable.current_location);
PickupLocationMarker = CommonUtils.createMultipleMarkers(globalGoogleMap, Double.valueOf(pickupLat), Double.valueOf(pickupLong), "Pickup Location", R.drawable.pickup_marker_icon);
DropLocationMarker = CommonUtils.createMultipleMarkers(globalGoogleMap, Double.valueOf(dropLong), Double.valueOf(dropLat), "Drop Location", R.drawable.drop_location_marker_icon);
}
} else {
Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Log.e("Exception", e.toString());
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error", error.toString());
}
});
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
queue.add(request);
}
请告诉我,我做错了什么?我们不应该总是打电话吗?或者我应该在单身人员课堂排球,这样我只能实例化一次?任何建议都可以。谢谢。
你甚至尝试过使用单身人士吗? –