I am working on an application where whole data came from the API. I mostly used fragment in my application at some fragment my application did not take too much time. But at some Fragment It take to much time to display the Layout. When I debug the application I saw that data has came rapidly but it take time to display the data . And in the Log I got a message "this Application doing lot of task in its main thread". Is there any way to improve the performance of the application ?
-
4move task away from main thread – Vivek Mishra Feb 21 '17 at 09:19
-
All networking task I did in background thread. – Abhishek Bhardwaj Feb 21 '17 at 09:21
-
As I told my application take time in displaying some data . Is this is the issue of complex layout? – Abhishek Bhardwaj Feb 21 '17 at 09:22
-
as you haven't posted any code (which you should) so it is just a wild guess. May be you are doing some other time taking tasks like fetching contacts etc. They should also be moved to background thread – Vivek Mishra Feb 21 '17 at 09:23
-
Do you use the attribute `weight` of `LinearLayout` ? – Raphael Teyssandier Feb 21 '17 at 09:23
-
Yes , I used. Is It creating issue? – Abhishek Bhardwaj Feb 21 '17 at 09:24
-
See : http://stackoverflow.com/questions/9430764/why-are-nested-weights-bad-for-performance-alternatives then use http://stackoverflow.com/a/36923661/4854450 – Raphael Teyssandier Feb 21 '17 at 09:26
3 Answers
you can use volley libraries to download data fast and for image use picaso and for database use relm database its fast api dont use old style httpcliant or json parser its slow.and first display data from database then store data of api in database and again dispaly from database in onpause method after some time(dippents on our data how much time tack to load ).if you have large data in json use pagination tachniq.

- 788
- 8
- 19
-
I used volley at some layout it work fine as I Mention above – Abhishek Bhardwaj Feb 21 '17 at 09:43
-
-
dislplay data first from db and store server datain background then display again after some time – android_jain Feb 21 '17 at 09:47
-
see json responce time in postman or any other tolll if json responce more then 2000 ms then you have to think about server responce – android_jain Feb 21 '17 at 10:02
In my case, I am facing the same issues when I try to parse the JSON Results as a markers in GoogleMap.For <1000 Json Objects it works fine But when the Json Result Object Exceeds >1000 my app gets hangs and it takes too much of time to load. Here What I have done to fix the issue
i am assuming you are deal with JSon Data.
Reduce the Size of JSon Results Based on Some Conditions.
Use small tags for JSon Lables(for Ex. instead of lable latitude use l,instead of longitude use lo)
Avoid HttpClient for Network Calls,Use Appropriate Network Library(like volly,Retrofit,OkHttp) based on Your Requirement NetworkLibraries Difference
If you have any Calculations with the Result data Try to done it from the Server side as much as Possible
- Remove Unwanted data in the JSON Result.

- 1
- 1

- 1,560
- 21
- 35
Please follow this guide line for Android app development Click here

- 2,521
- 1
- 19
- 33