NetworkOnMainThreadException on higher SDK's

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

Just discovered that the http library causes a problem on higher SDK's/API's. Code that worked for last 6 months on older devices causes a problem in for example ICS. See here for more documentation: NetworkOnMainThreadException | Android Developers

Higher SDK's shouldn't do networking anymore on the main thread. How can we solve this issue?
 

bluedude

Well-Known Member
Licensed User
Longtime User
Erel, http Utils will not work in my situation (we have a discussion on that in the past).

Will need to see what I need to change, it's a lot of code that makes calls to API's that return a string result.

I thought it was already async because sometimes it takes 5-10 seconds and my app. continues.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
So do I need to save all JSON results in in a stream text file then and open it to process when finished? Or can I do it in memory?
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Well, it suddenly becomes much more complicated then. Basically I have 3-4 API's that return data and some fast after each other (validation and data). I recognize these using the TaskID (every API has a task ID). That would mean data cannot be stored in the same buffer (otherwise I don't know what is what) and mostly I don't know how big the returned data is. I use this for example for Twitter, Foursquare etc.

Can a Byte array be stored in a Map with a key?
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Not sure how keeping it on v11 will work with Ice Cream Sandwich? Top priority is the speed of the response showing.

Overall it use around 15 different API calls per application, I will test what is the best approach and gives me the best performance and what is the best scenario.

Async calls are not always returning in the sequence called, so it could give me strange results.

Cheers,
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
I know but what if I want to use newer API stuff? So I guess I need to do my test cycle again with Async. Will take a while because of multiple API's and some called right after each other.

Anyway, will solve it hopefully. Its not getting easier :)
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Erel,

Solved the problem for now. As always I should listen to you, rewritten the response stuff to Async and it works like a breeze.

Cheers,
 
Upvote 0
Top