Parsing XML performance issue Android - android

I send a request off to our server and receive a response from the server. The response contains information related to an image. The server returns the image as a base64 string. It is taking way to long (30-40 seconds per image) to parse out the data so I can pull the information I need to save and view the image. I am looking for suggestions on better ways that might help to speed up the process. I am currently using a SAX parser and the slow down is when the .parse function is called.

Related

Getting image url from json is better or using an encoded image within json?

I have a json from server in which the image urls are send from server but i want to know if i ask my php developer person to send encoded image in json would be a better approch or the former one ?
I want to load the images in listview after that.
Thanks in Advance.
getting url will be better and clean approach.it will make your response compact and image url can be loaded any time you want where if you transmit encoded image it has to be transmitted in network even if you dont want to display at the time.

Json parse much time

I am developing a map application and I parse one json file and after I take some data from this file I use the data to parse another json twenty times and I do this in one asynctask and it takes too long if I dont connect to internet on wifi(with mobil network).What is the best approach to reduce the time elapsed?Can anyone help?

Send long string (Base64 encoded image) via HttpGet

I'm trying to send an image as a Base64 encoded string to my PHP script via HttpGet, but as I kind of expected I get a 414 URI too large from my server.
Is there a way to post large strings with HttpGet?
Any help is greatly appreciated.
URI limit depends on server settings and its not a good idea to send huge data via Get method. And no, you cant use Post on Get service.
The best would be to alter your webservice to receive Post request and then you may send as long data as you want
when the URI is too large (cause of you are using it to send an image...) all you can do is to try to make it smaller, by compressing it. Or if you have access to the server, increase the limit....
the one way or the other.... use http-post instead of http-get.
you wont have the problem that the size is limited (or if theres a limit, its way bigger then the one from http-get) and i cant believe that sending an image via http-get is usage as intended by the http

Getting incomplete xml data from web-service

I am sending a POST request to a web-service which returns data in XML format. When I invoke the web-service via the browser i can see the complete XML file. However, when I call the web-service from my android app (in emulator) I only get partial XML data?
The size of the XML file being sent is approx 14500 bytes. I first store the response in a byte array whose size i calculate using getContentLength() function. This method returns the correct size of the response.
However, my InputStreamReader reads approximately 6350 bytes of the actual data to the byte array. The remaining part of the byte array simply contains zeros.
I tried looking everywhere online but so far I haven't come across a solution. Yes chunking is one option but since I dont have access to the web-service code I can't implement that option.
Really appreciate if someone could guide me here!
I don't understand why do you need to use InputStreamReader (which can behave very wrong if you are not careful) to read web service data (in your case it is only around 14.5kb). Just use HttpURLConnection, connect to your ws, and it will take care for you about the connection and also the response connection.getResponseMessage();

Parse simple string JSon in Android

I have the following code:
String response = webService.webGet(""); the response of the web service
String LargeImage = new Gson().fromJson(response,String.class);
byte[] imageByteArray = Base64.decode(LargeImage);
response is like: "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCA... " a Base64 encoded image having around 400.000 characters.
The response comes very quick from the web service. When it tries to parse it with Gson after a while (like 20-30 seconds) I get an error with out of memory. How can I parse this simple string without Gson, it should be fairly simple but I don't know how to do it.
Please advise me. Thank you for your time
Change your Base64 image encoding into a URL where you can download the image directly.
Then go get flexjson 2.1 and you can parse JSON on Android very easily in a few lines. It's also faster than GSON.
http://flexjson.sourceforge.net
But from your post it looks like you're just sending the Base64 image over JSON as a single string. No need to use JSON in that case. Unless you plan on wrapping some metadata around it in the future.
Also skip storing the image in the DB. Just write it to the filesystem, and put the file path in the DB linked to your object. Much easier to debug when you wonder what image you downloaded, etc.
response is like: "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCA... " a Base64 encoded image having around 400.000 characters.
You have got to be kidding me.
Please advise me.
Find a sensible Web service and switch to it. If somebody at your firm wrote the Web service, fire them. If you wrote the Web service, fire yourself. I see no need to be returning an image -- particularly one that massive -- in Base64 encoding, wrapped in JSON.
In the meantime, you could try the built-in Android JSON parser rather than Gson.

Categories

Resources