Memory error in Android app when consulting more than 500 contacts

2

I have an app about to go to the market but I have a problem that I do not know how to solve.

  

When I make an inquiry from the contacts of the phone from the app, if the user has more than 500 contacts, the app remains frozen.

Do you know any way in android studio, to give more memory of the phone to my app and thus avoid this error?

I do the contact consultation to know which contacts on the phone my app already has and thus put them as friends. This way you can invite them inside the app. Thanks

I leave here the error

  

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals (java.lang.Object)' on a null object reference       at en.totdemas.totdemas.Menu $ 40.onPostExecute (Menu.java:956)       at en.totdemas.totdemas.Menu $ 40.onPostExecute (Menu.java:925)       at android.os.AsyncTask.finish (AsyncTask.java:632)       at android.os.AsyncTask.access $ 600 (AsyncTask.java:177)       at android.os.AsyncTask $ InternalHandler.handleMessage (AsyncTask.java:645)       at android.os.Handler.dispatchMessage (Handler.java:102)       at android.os.Looper.loop (Looper.java:145)       at android.app.ActivityThread.main (ActivityThread.java:5942)       at java.lang.reflect.Method.invoke (Native Method)       at java.lang.reflect.Method.invoke (Method.java:372)       at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1400)       at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1195)

    
asked by MB_plus 06.04.2017 в 20:45
source

1 answer

0

I do not know how you do the query itself, but a select name of 500 is not the same as a select * of 500. I do not think you should do a 500 query in a tiron, I'm not enough in android to to know if this solution is viable but I would make the consultations little by little. Let's take as an example a known app, the whatsapp. This does not show you your contacts. It looks for you or shows the first 10 or 20 and when you scroll and arrive at those last ones it sends a request of the following ones and so on until infinity.

In this way, not only will the application not be lagged, but it will be more scalable because it consumes less resources from the server when asking questions and even older mobiles will be able to make those queries and support the load.

I hope I have helped you and that you understand me.

    
answered by 07.04.2017 в 00:40