private Runnable readingRun = new Runnable() { public void run() { try { InputStream input; input = s.getInputStream(); int readBytes; byte[] buffer = new byte[1024]; while (((readBytes = input.read(buffer)) != 0)) { if (readBytes!= 0) { String receivedStr = new String(buffer, 0, readBytes, "UTF-8"); String[] Analyse = receivedStr.split("#"); if (Analyse[0].equals("ConnexionAndroid")){ runOnUiThread(new Runnable() { public void run() { Toast Annonce = Toast.makeText( getApplicationContext() , "Reception message serveur connexion" , Toast.LENGTH_SHORT );Annonce.show(); } }); } } else break; } } catch (IOException e) { e.printStackTrace(); } } };
readingThread = new Thread(readingRun); readingThread.start();
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
à l'arrache dans le code ?
/* inside your non-UI thread */ leBouton.post(new Runnable() { public void run() { // action de refresh and co } });
private Runnable readingRun = new Runnable() { public void run() { try { InputStream input; input = s.getInputStream(); int readBytes; byte[] buffer = new byte[1024]; while (((readBytes = input.read(buffer)) != 0)) { if (readBytes!= 0) { String receivedStr = new String(buffer, 0, readBytes, "UTF-8"); String[] Analyse = receivedStr.split("#"); if (Analyse[0].equals("ConnexionAndroid")){ Toast Annonce = Toast.makeText( getApplicationContext() , "Reception message serveur connexion" , Toast.LENGTH_SHORT );Annonce.show(); } } else break; } } catch (IOException e) { e.printStackTrace(); } } };