3

I have a Page Viewer and inside every page I have list View , this list view will have 10 records using a web service , so the page viewer use three calls of the web service to populate three pages (the current , the left and the right page) but after I make a lot of swipes I am getting this exception :

java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
            at java.lang.VMThread.create(Native Method)
            at java.lang.Thread.start(Thread.java:1029)
            at com.android.volley.RequestQueue.start(RequestQueue.java:142)
            at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:66)
            at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:78)
            at com.imona.android.entities.Record.<init>(Record.java:57)
            at com.imona.android.webservices.OperationalDataRest$1.onResponse(OperationalDataRest.java:109)
            at com.imona.android.webservices.OperationalDataRest$1.onResponse(OperationalDataRest.java:85)
            at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
            at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method) 

2 Answers2

9

How do you initialize your RequestQueue? I suspect that you are creating RequestQueues for each tab. If that's the case, change your program to use one common instance of RequestQueue from all the tabs. You need to initialize and retain it in your activity and add requests to it from each tab.

Yuichi Araki
  • 3,438
  • 1
  • 19
  • 24
  • but I thought that Request Queue is singleton and I will not have another instance of it ? and if not you mean it is possible to have multiple request in the same time to the server called by multiple request queues. is it right ? – Mohammed Subhi Sheikh Quroush Jan 31 '14 at 09:23
  • I discovered the answer before watching your post However thanks very much, it was Great answer :) – Mohammed Subhi Sheikh Quroush Jan 31 '14 at 09:24
  • How do I do this? Is there any example of this? I'm facing the same problem. I guess it is because I put too many instances of Volleys in an activity. – emen Aug 13 '14 at 07:53
  • I also face this type of problem. if any one have example then please let us know to understand what happen. In my case I make base class of volley and it extends every activity and I pass each time context to volley function. detail code is here http://androidpostbybhavik.blogspot.in/2015/11/generalize-web-api-calling-using-google.html?view=classic – Bhavikkumar Dec 25 '15 at 05:26
4

I used static queue instead of creating new queue in my Record class

I changed code from

public class Record {

    private RequestQueue RecordSyncQueue = Volley.newRequestQueue(ImonaAndroidApp.app);

}

to

public class Record {

    private static RequestQueue RecordSyncQueue = Volley.newRequestQueue(ImonaAndroidApp.app);

}