private class ImageTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { for(int i=0; i<5; i++) { if (status == 0) { //image.setImageResource(R.drawable.zeena1); status = 1; } else { //image.setImageResource(R.drawable.ic_localobidos); status = 0; } try { publishProgress(); Thread.sleep(2000); } catch (InterruptedException ex) { //Toast.makeText(null, "Errore Thread: " + ex.getMessage(), Toast.LENGTH_LONG).show(); } } return "Executed"; } @Override protected void onProgressUpdate(Void... values) { //super.onProgressUpdate(values); if (status == 1) image.setImageResource(R.drawable.zeena1); else image.setImageResource(R.drawable.ic_localobidos); } @Override protected void onPostExecute(String result) { image.setImageResource(R.drawable.zeena1); } }
private class SocketTask extends AsyncTask<String, Void, String> { private String message; private Socket socket; private BufferedReader buffer; private PrintWriter pwrite; public SocketTask(String message) { this.message = message; // try { // socket = new Socket("192.168.0.3", 10100); // buffer = new BufferedReader(new InputStreamReader(socket.getInputStream())); // pwrite = new PrintWriter(socket.getOutputStream()); // } // catch(Exception ex) { // System.out.println(ex.getMessage()); // } } @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected String doInBackground(String... params) { try { socket = new Socket("192.168.0.3", 10100); buffer = new BufferedReader(new InputStreamReader(socket.getInputStream())); pwrite = new PrintWriter(socket.getOutputStream()); pwrite.println("provaprova"); pwrite.flush(); String s = buffer.readLine(); message = s; //publishProgress(); } catch(Exception ex) { System.out.println(ex.getMessage()); } return "Executed"; } // @Override // protected void onProgressUpdate(Void... values) { // super.onProgressUpdate(values); // TextView msg = (TextView) findViewById(R.id.message); // msg.setText(message); // } @Override protected void onPostExecute(String result) { TextView msg = (TextView) findViewById(R.id.message); msg.setText(message + " " + result); } }