Json Object Size Limitation Android - android

i have one big question, please suggest me what is the maximum responded (Server response) json object recommended size for android device ?
I have json Object size is 15 mb approximately, Is it Good for Android Mobile for analysis ???
Ya its required small json object for analysis for performance issue ???

Its Not Better Solution to Get Response of !5 mb .
if You Done This Then So many Issue Ocure like OutofMemory
other is Like Long Execution Time
user inherit From your app cause of Long waiting delay
thats y my suggestion is that you have to use pagination or load more data and retrive very samll json

Related

how to parse huge (>50mb) JSON file

How to parse data >50mb .There is zip inside json file which is more than 50 mb.please help me to solve this problem i will get out of memory error while parsing.
You should use Gson or Jackson for this purpose. note.. I have no clue how but you would do great with a pointer.
Loading a 50 mb file all at once would be a problem to the device due to the following :
Large file ... Lots of time to load , affects the users expression towards your app if its public.
Parsing , a 50 mb json file is nothing but 50 mb of arrays . It might not be a good idea to parse it all at once. Note.. Make sure you google on ways to avoid garbage collection.
Now ,
Why Gson or Jackson ?
Well , normally if you would parse a json file it would load it all at once taking a lot of time as well as affecting the memory consumption.
With the help of these , you can load off only a few items in the json file at a time..this is called json streaming.
For example you can use it while loading a product list , loading off a few products into the list as you scroll .

Give me a suggestion to improve my app performance, on retrieving huge data(nearly more than 10,000 records) from server?

On performance view, JSON parsing take huge time for retrieving Data.In my app i need to get nearly 10,000 records from Server.On emulator,it gets data immediately and works efficiently.But in my android phone,it takes more than 2 minutes to retrieve all data.Kindly,give me a suggestion for improve the performance on phone.
The emulator has access to your host machine's resources and is therefore not a good way to test performance.
I have used the Jackson streaming JSON parser with large data sets and it works well for me. However, I run this process in the background and am able to accept long fetch/parse times. Depending on the size of the data and the speed of the device you're running on, 2 minutes does not seem extraordinarily long to me.
Maybe you could fetch a smaller subset of the data first, and then display it while you fetch the rest in the background. You're probably going to have to do some kind of optimization like this in order to improve performance.
I think you can parse the complex JSON response using GSON. Please check these tutorial http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
You just create the model classes and use the proper annotations then the data will be parsed to model objects directly.
The question is, what causes this slowdown. Because of everything goes in the rmulator like charm, it is probably the network speed. You can help this if you find a solution to compress the json data.
It is a text, with a lot of repeat, it is very, very good compressable. And http supports compression.
You need to set it in your http server.
If you find this a promising direction, I suggest to make a new question, giving your http server version. Good luck!

SAX parser takes a lot of time to parse

I have created an application where I parse data from server using SAX parser. I followed this link
It works fine but it took a lot of time. I need to reduce time taken to parse stuff.
Any pro-tips?
The obvious tip is: profile your code and determine where the time is going. Perhaps you are doing a lot of work handling some of the SAX events. Perhaps the time is being spent doing something entirely unrelated to the parsing. You can't tell until you profile.
Like Ted said, profile your code.
Are you sure its the parse time and not the load time? Are you on wifi or a mobile network? How quickly are other apps loading their data?
That said, don't use that many ArrayList objects, a single array list with a custom container type (i.e. a Ticket object has a price and date, no need to have a price array and date array).
Check you memory usage, usually if things are slow you are generating a ton of garbage. (look for the GC in the log)
Use the final keyword for String parameters that won't change. So setString(final String s) instead of setString(String s). This should prevent the Strings from being duplicated when passed as parameters.
Use JSON instead of XML if you can, its more light weight.
After you've made any significant change, profile your code again

Android uploading pictures to server in most efficient way

I need to get images along with other data (very similar to email with attachements) to the server. I also need to do it in reliable manner so I can retry, etc on failure.
Server is WCF REST server and I do lot of other communications with it(JSON) but just got this new requirement to upload images.
Since I use JSON to post data to my server - I use GSON on Android side to serialize data.
Here is how I got it implemented so far (everything else works this way but I just started with images)
User filling activity fields (text data)
User takes some picture(s) via camera intents. Currently I just use 1 file for pictures
I take picture from SDCard, load/resize it - dispaly on ImageView and store in byte[]
User submits - I take all data along with images from byte[] and put it into Java object
Call GSON converter and serialize object
Save object into SQLite
AsyncTask looks in SQLite for records, opens cursor and get's text
AsyncTask creates HttpConnection and posts text data to my server.
THE END
Now to my problems..
Obviously on #3 - I "explode" ram with my byte arrays. Sometime I even feel my Nexus S becomes sluggish. But by doing that - I avoid filling SD card or app folder with many files. I take picture and than grab it. Next picture will overwrite previous one.
Step #5 IS slow. I didn't try custom serializer on GSON and instead of serializing byte array into something like [1,-100,123,-12] I can get much smaller size with Base64 but still. It will be slow. And I can have up to 20 images...
Step #6 is no problem. But with certain size (I tried 300px image) I started to get error in step 7 on OpenCursor
07-06 20:28:47.113: ERROR/CursorWindow(16292): need to grow: mSize = 1048576, size = 925630, freeSpace() = 402958, numRows = 2
07-06 20:28:47.113: ERROR/CursorWindow(16292): not growing since there are already 2 row(s), max size 1048576
07-06 20:28:47.113: ERROR/Cursor(16292): Failed allocating 925630 bytes for text/blob at 1,1
So, this whole thing is not something I like. Ideally I want all data to be uploaded in single piece to server.
I was thinking maybe storing images timestamped on SD card and store only their name in DB. Than I would process them right before sending to server. And on success I would delete those images. This kind of logic will make SQLite schema much more complex but maybe there is no better way?!
I guess I'm looking for best practice to deal with images. How to do followin with minimal memory/CPU usage:
Take picture
Display thumbnail
Resize
Send to server
EDIT 1:
Currently I'm researching possibility of uploading whole shizang as a multi-part MIME message. That would require adding some JAR's to my Android package. Also I'm not sure how effective will be Apache code to load images and sending them(I guess better than my code)
http://okandroidletsgo.wordpress.com/2011/05/30/android-to-wcf-streaming-multi-part-binary-images/
And that I would have to deal with parsing all this on WCF side since there is no way to do it with built-on .NET framework.
http://antscode.blogspot.com/2009/11/parsing-multipart-form-data-in-wcf.html
PLEASE TELL ME IF YOU TRIED THIS!
EDIT 2:
MIME is no good. There is no point since it serializes binary using Base64 which is same thing..
Nobody answered but here is what I figured hard way:
Rule #1: When dealing with images - avoid using objects/memory. Sounds obvious but it's not. I figured that resizing image to 800x600 is OK. Anything bigger - you may consider just leaving it as is because it is possible to do http stream on bigger file but it's hard to work with OOM exceptions when you load images into memory for processing
Rule #2: When use GSON - use JsonWriter to populate stream. Otherwise memory will explode. Than pass that stream into HttpClient. JsonWriter will write in chunks and data will be sent as it process.
Rule #3: See rule #2. It will work OK for multiple small images. This way GSON will serialize them 1 by one and feed into stream. Each image WILL be loaded int memory anyway.
Rule #4: This is probably the best solution but requires more coordination with server. Images sent 1 by 1 before message sent to server. They sent as stream without any encoding. This way they don't have to be base64 encoded and they don't have to be loaded in memory on device. Size of transmission will be smaller as well. When all images sent - post main informational object and collect all package together on server.
Rule #5: Forget about storing BLOB in SQLite
Bottom line:
It is much cheaper in term of resources to send images WITHOUT any resizing. Resizing makes sense only when Image get's to about 800x600-ish
Sending multiple images in a single package makes sense when image get's small like 600x400-ish
As soon as you need to upload files - start thinking streams everywhere. DO NOT load stuff into memory.

Json read error?

Hi friends I am getting the value from webservice while json value .I am storing in stringBuffer . I am getting the lot of value from webservice .so I am getting out of memory error .can any body tell how to avoid that?
Thank you,
You can allocate the StringBuffer with more amount of size, or try to implement paging or lazy loading..
But, with a lot of value, I think it's not good to use JSon
Json is stored in memory and simply lot of data from server cause out of memory exception. Better idea is to download data in chunks and store in database.
To do it use Jackson library that support streaming data or JsonReader but it is only in Android 3.0.

Categories

Resources