I have this strange problem. I am retrieving twitters and it works on the Emulator and also on my Samsung Galaxy S but it doesn’t work on my Galaxy Tab 10.1 ?
Same app installed on both the phone and the tab. Generated from Eclipse so no debugging or anything.
Different permissions needed?
This is the code:
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(searchUrl);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseBody = client.execute(get, responseHandler);
and this is the manifest:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
I swear, this question is asked everyday here on StackOverflow. 🙂
The problem is that you are performing a network access on the main UI thread. Android 3.0 and above will crash your application (i.e. the system will throw a
NetworkAccessOnMainThreadexception) if you attempt to perform an HTTP request on the main thread. You need to wrap your HTTP request in anAsyncTask(or aThreadof some sorts) to ensure that you don’t block the UI thread.Read my blog post on the subject:
Why Ice Cream Sandwich Crashes Your App