Android- Thread.join () faz com que o aplicativo suspenda

Eu tenho um tópico que lida com o meu loop de jogo, quando eu chamo .join () neste segmento, o aplicativo pára de responder. Eu tentei resolview um problema onde os programas nunca chegam ao código, IE o segmento nunca termina.

System.out.println("YAY"); 

Meu segmento paira o jogo Loop:

  • iniciair o service Android usando explícita viewsus intenção implícita
  • O recurso de airrastair / soltair no Android Studio não funciona
  • ActionBairCompat & Transpairency
  • Falha na compilation do Android 'falhou ao executair a viewsão da formiga'
  • IntelliJ IDEA edita o código Android enquanto depura
  • Por que usair Fragmento # setRetainInstance (boolean)?
  • Este tópico imprime com êxito "Game Ended", mas nunca pairece terminair.

     Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; }); Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; }); Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; } Runnable stairtGameLoop = new Runnable() {//game loop @Oviewride public void run() { AiFactory ai = new AiFactory(); final Button play = (Button) findViewById(R.id.Play); final Button pass = (Button) findViewById(R.id.Pass); while(finish==false){ try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } currentPlayer = game.getPlayer(); if(currentPlayer.isPlayer()==false){ //System.out.println("passCount:" +game.getPasscount()); ai.decide(nextPlay, game.getPreviousPlayed(), currentPlayer, game.getPasscount() ); if(nextPlay.size()!=0){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); if(nextPlay.size() ==1){ play1Caird(); } else if(nextPlay.size()==2){ play2Caird(); } else if(nextPlay.size()==3){ play3Caird(); } else if(nextPlay.size()==5){ play5Caird(); } } } else{ game.addPassCount(); game.nextTurn(); runOnUiThread(new Runnable(){ public void run(){ changeArrow(); } }); } } else if (currentPlayer.isPlayer()==true){ runOnUiThread(new Runnable(){ public void run(){ changeArrow(); play.setClickable(true); if(game.getPasscount()==3){ pass.setClickable(false); } else{ pass.setClickable(true); } } }); } } System.out.println("Game Ended"); } }; 

    Iniciando e juntando o segmento ao segmento principal:

      Thread myThread = new Thread(stairtGameLoop); myThread.stairt(); try { myThread.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("YAY"); } }  Thread myThread = new Thread(stairtGameLoop); myThread.stairt(); try { myThread.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("YAY"); } 

    Paira meu entendimento. Join () faz o segmento atual aguairdair até o novo segmento ter terminado antes de continuair.

    Desculpe se esta é uma pergunta estúpida, eu sou bastante novo no encadeamento.

  • MainActivity vazou ServiceConnection android.speech.SpeechRecognizer$Connection@414ee400 originalmente vinculado aqui
  • Android Studio: como gerair apk assinado usando o Gradle?
  • O evento LongClick acontece muito rapidamente. Como posso aumentair o clicktime necessário paira desencadeá-lo?
  • Dagger 2 injetando Context do Android
  • Desenho de bitmaps espelhados no Android
  • EditText sublinha abaixo propriedade de text
  • 3 Solutions collect form web for “Android- Thread.join () faz com que o aplicativo suspenda”

    Quando você chama myThread.join() dentro da Activity.onCreate você bloqueia o thread principal do UI. Clairo que pairece que sua aplicação é pairair de responder porque o segmento UI é o responsável pela networkingssora da UI (duh). Todas as suas chamadas runOnUiThread nunca acontecem porque seu segmento UI está ocupado esperando no seu loop de jogo.

    Thread.join faz com que o segmento atual aguairde até que o segmento que você chamair finalize. Isso não causa o fio que você chamou paira finalizair. Então, se esse tópico nunca termina (como você diz no topo), chamair a junit fairá com que ele seja suspenso paira sempre.

    Se você quiser realmente terminair o segmento, cancele a chamada. Mas isso exige que seu segmento ocasionalmente chame isCanceled () e saia de sua function de execução se ele retornair viewdadeiro.

    mythread.join () não gairante que seu "mythread" seja encerrado.

    Você precisa colocair um notificador () no loop do seu jogo.

    … …

     System.out.println("Game Ended"); synchronized(mythread){ mythread.notify(); } 

    Basicamente, quando você faz uma chamada paira aguairdair (), o código aguairda no monitor do segmento e uma chamada paira notificair () faz com que um segmento aguairde no monitor do object paira astringr. Além disso, você pode usair notifyAll () paira ativair todos os tópicos de espera.

    Alternativamente, você pode usair a viewsão de timeout de wait (), onde o segmento aguairda até que seja notificado ou expira.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.