Do your network operations on a background thread or disable StrictMode
Instead of calling senddata
as you currently do (I don't know which function you're calling it from, but that function is running on the UI thread), try calling it in an AsyncTask
like this:
someFunctionOnTheUIThread()
{
//senddata(); //this is your current senddata() call. Replace it with the following
(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
senddata();
return null;
}
}).execute((Void)null);
}
As stated in the beginning, you can also disable StrictMode
, but it's highly unrecommended as it'll block the UI, you'll get ANRs (Application Not Responding) when the network is slow (or the request "hangs" - it can happen even on good networks and, if it does, the default timeout for the request is, AFAIK and assuming you haven't changed it, 30 seconds ).
Please look at other questions asked about this on StackOverflow. There are a lot of useful and more detailed answers for this. Also, for future questions, please check to see if your question has already been asked here by another person before posting it. It'll lower the amount of duplicate questions and it won't get you down-voted (and your question closed and marked as a duplicate).