You are attempting to make a connection on the UI thread and ICS is crashing your app (as it should, since attempting to connect to a web server on the UI thread is almost certainly a guarantee that your app will not function correctly). Ensure that you are making the connection using an AsyncTask
or a Thread
.
Edit:
You asked for some clarification, so here it goes. From an Android article on the Developer's site:
When an application is launched, the system creates a thread called
"main" for the application. The main thread, also called the UI
thread, is very important because it is in charge of dispatching the
events to the appropriate widgets, including drawing events. It is
also the thread where your application interacts with running
components of the Android UI toolkit.
For instance, if you touch the a button on screen, the UI thread
dispatches the touch event to the widget, which in turn sets its
pressed state and posts an invalidate request to the event queue. The
UI thread dequeues the request and notifies the widget to redraw
itself.
This single-thread model can yield poor performance unless your
application is implemented properly. Specifically, if everything is
happening in a single thread, performing long operations such as
network access or database queries on the UI thread will block the
whole user interface. No event can be dispatched, including drawing
events, while the long operation is underway. From the user's
perspective, the application appears hung. Even worse, if the UI
thread is blocked for more than a few seconds (about 5 seconds
currently) the user is presented with the infamous "application not
responding" (ANR) dialog.
This applies to your situation, as attempting to establish a socket connection between a client and a server will block the UI Thread--the user will not be able to interact with the screen at all until the connection is made (and this won't get you too many good reviews in the Android Market :P). Therefore, it is very important to perform potentially expensive/long-term operations on a separate Thread. The easiest way to do this is to use an AsyncTask
, which are very easy to implement and essentially abstract the entire idea of Thread
s so you don't have to worry about it.