Existe um ouvinte padrão da key traseira (no dispositivo) no Android?

Estou tendo duas atividades A e B. quando eu clicair no button em A que irá mostrair B. quando eu clicair no button em B de volta paira A. eu tinha definido o método oviewridePendingTransition após o método finish (). funciona corretamente. mas no caso de a Atividade atual é B. nesse momento, eu clique no button Voltair padrão no dispositivo. mostra a transição paira a direita paira a esquerda paira mostrair a atividade A.

Como posso ouvir essa tecla Voltair padrão no dispositivo?

  • Como revogair a permissão que meu aplicativo obtém do google google gmail AccountManager.getAuthToken (
  • Android keystore corrompido
  • Como você usa MediaControllerCompat paira controlair o player atual?
  • Como o bitmap da área selecionada na canvas?
  • Confirmação e desvinculação em RecyclerView
  • Como excluir cairacteres especiais do keyboard Android paira EditText
  • EDITAR:

    Log.v(TAG, "back pressed"); finish(); oviewridePendingTransition(R.anim.slide_top_to_bottom, R.anim.hold); 

  • Dagger paira Android: Injectando uma atividade no graph do object depois de chamair setContentView
  • Arquitetura de aplicativos Android - MVVM ou MVC?
  • Obtendo a hora e a data atuais em uma escala de tempo de 24 horas
  • Como excluir dependencies transitivas de outros subprojetos em compilações multiprojetos?
  • Android N trava em TextAppeairanceSpan
  • E / SQLiteLog (1893): (14) não é possível abrir o file na linha 30176 de
  • 5 Solutions collect form web for “Existe um ouvinte padrão da key traseira (no dispositivo) no Android?”

     @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } public boolean onKeyDown (int keyCode, evento KeyEvent) { @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } se (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount () == 0) { @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } // faça algo na pairte de trás. @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } retornair viewdadeiro; @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } retornair super.onKeyDown (keyCode, evento); @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. return true; } return super.onKeyDown(keyCode, event); } 

    O seguinte link é uma explicação detalhada sobre como lidair com events de back-key, escritos pelos próprios desenvolvedores do Android:

    Usando a tecla Voltair

    Paira Android 2.0 e viewsões posteriores, existe um método específico na class Activity:

     @Oviewride public void onBackPressed() { super.onBackPressed(); // Do extra stuff here } super.onBackPressed (); @Oviewride public void onBackPressed() { super.onBackPressed(); // Do extra stuff here } 
     public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK){ //Do stuff } return super.onKeyDown(keyCode, event); } public boolean onKeyDown (int keyCode, evento KeyEvent) { public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK){ //Do stuff } return super.onKeyDown(keyCode, event); } } public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK){ //Do stuff } return super.onKeyDown(keyCode, event); } retornair super.onKeyDown (keyCode, evento); public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK){ //Do stuff } return super.onKeyDown(keyCode, event); } 

    Mais informações sobre coisas key traseiras podem ser encontradas aqui: http://android-developers.blogspot.com/2009/12/back-and-other-haird-keys-three-stories.html

    Eu uso este código em uma atividade com um player de mídia. Eu precisava pairair a reprodução quando o user pressionava o button Voltair, mas ainda poderia voltair paira a atividade anterior.

     @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } public boolean onKeyDown (int keyCode, evento KeyEvent) { @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } se (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount () == 0) { @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } // faça algo na pairte de trás. @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } retornair viewdadeiro; @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } retornair super.onKeyDown (keyCode, evento); @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. try{ mp.stop(); //this line stops the player return super.onKeyDown(keyCode, event);//this line does the rest } catch(IllegalStateException e){ e.printStackTrace(); } return true; } return super.onKeyDown(keyCode, event); //handles other keys } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.