There is a code for sending a request to the server as a result of which comes result with a number (1 or 0). How to perform a second request in case of a 1?
public class JSON extends AsyncTask<String, String, String> { @Override protected String doInBackground(String... params) { HttpURLConnection connection = null; BufferedReader reader = null; while (true) { startLoop(); try { URL url = new URL("site"); connection = (HttpURLConnection) url.openConnection(); connection.connect(); InputStream stream = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(stream)); StringBuffer buffer = new StringBuffer(); String line = ""; while ((line = reader.readLine()) != null) { buffer.append(line); } return buffer.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } return null; } } @Override protected void onPostExecute(String result) { super.onPostExecute(result); if (result.contains("1")) { new JSONTask().execute(a); //startTell(); } else { } }
AsyncTaskand that's it. - Eugene Krivenja