I execute a post request in another thread using AsyncTask, while it is executed, the progress bar is spinning, I turn off the application, turn off the wifi, the application crashes! Interested in 2 questions, is it possible to monitor the presence of a connection in real time and how to interrupt the request?
protected Void doInBackground (String... params) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(УРЛ); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("login", "майлогин")); nameValuePairs.add(new BasicNameValuePair("pass", "майпасс")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); String str = new String(); str = EntityUtils.toString(response.getEntity()); publishProgress(str); } catch (ClientProtocolException e) { } catch (IOException e) { Toast.makeText(SigiActivity.this, "Ошибка : " + e.getMessage(), Toast.LENGTH_LONG).show(); } return null; }