1

When I remove the requestQuery.add() line - all works fine except absence of network data. After adding requestQuery.add() - I'm getting this:

Traceback:

08-29 18:15:53.071    6305-7075/? E/dalvikvm-heap﹕ Out of memory on a 840969348-byte allocation.
    08-29 18:15:53.141    6305-7075/? E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-27227
        java.lang.OutOfMemoryError
                at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:322)
                at com.android.volley.toolbox.DiskBasedCache.readString(DiskBasedCache.java:540)
                at com.android.volley.toolbox.DiskBasedCache.readStringStringMap(DiskBasedCache.java:562)
                at com.android.volley.toolbox.DiskBasedCache$CacheHeader.readHeader(DiskBasedCache.java:403)
                at com.android.volley.toolbox.DiskBasedCache.initialize(DiskBasedCache.java:156)
                at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:84)

Here's the code I have:

public class DataReceiver {
    public static void initializeCountriesListUpdate(String urlString, final Context context) throws IOException {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, urlString,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            ArrayList<Country> countriesList = JsonParser.getCountriesFromJson(response, context);

                            ((CountriesListActivity)context).updateCountriesList(countriesList);
                            ((CountriesListActivity)context).progressDialog.hide();
                            ((CountriesListActivity)context).progressDialog.dismiss();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("NetworkManager", "Cannot resolve data from the server");
            }
        });
        VolleySingleton.getInstance().getRequestQueue().add(jsonObjectRequest);
    }

UPD1:

I tried to add

    android:hardwareAccelerated="false"
    android:largeHeap="true"

to Manifest, but it doesn't helped.

Vassily
  • 5,263
  • 4
  • 33
  • 63
  • did you analyze your heap dump? – spiderman Aug 29 '15 at 12:35
  • My problem was an absence.of cache. Thanks to Udi for link hint. This manual helped me to make.my singleton correct: https://developer.android.com/training/volley/requestqueue.html#singleton – Vassily Aug 30 '15 at 20:35

2 Answers2

1

I would suspect your main issue is the memory exception, and as a side effect you get the exception regarding the ProgressDialog while trying to Remove the view after you've already got the OutOfMemoryError exception (this is the "has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41dbc578 V.E..... R......D 0,0-684,192} that was originally added here" part).

As the main Exception suggests your cache is probably larger than the Heap and your responses from the server are quite large and you should focus on resovling this issue.

I think this question might help you resolve this issue.

Community
  • 1
  • 1
SuperFrog
  • 7,631
  • 9
  • 51
  • 81
0

Bitmaps often cause the outofmemory error. Try leaving out the bitmap loading to test if that is the issue. Check there size, and maybe use the calculateInSampleSize as described here http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

matty357
  • 637
  • 4
  • 16