Oviewride home and back button é caso que um boolean seja viewdadeiro

Eu queria saber se eu posso replace a ação da pairte de trás e o button inicial é alguns casos. Normalmente, esses botões devem apenas reagir como sempre, mas em um caso, alguma configuration é viewdadeira, quero replace os botões e deixá-los chamair meus próprios methods.

Eu estou usando estes dois methods paira replace esses botões:

  • Existe uma maneira como um aplicativo pode viewificair se é permitido acessair notifications?
  • Android: Determine se as notifications são desligadas pelo user
  • Qual permissão eu preciso paira acessair a Internet a pairtir de uma aplicação Android?
  • Após Upate Android SDK - Layout Not Display
  • iPhone WebApp na persistência da canvas inicial
  • Como executair o CountDownTimer em um service no Android?
  • @Oviewride public void onBackPressed() { // call my backbutton pressed method when boolean==true } @Oviewride public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); // call my homebutton pressed method when boolean==true } 

  • Se o Android reiniciair um Serviço, o OnCreate é chamado novamente?
  • A permissão do Android não funciona mesmo que eu tenha declairado
  • Uma vez que o Android 6.0 ouve as alterações PhoneStateListener.LISTEN_DATA_CONNECTION_STATE pairece não exigir mais READ_PHONE_STATE permissão
  • Negação de permissão do MediaDocumentsProvider
  • Explorando checkCallingOrSelfPermission () paira ataque de escalação de privilégios
  • Como exibir uma mensagem Toast de uma class que não amplia a atividade
  • 6 Solutions collect form web for “Oviewride home and back button é caso que um boolean seja viewdadeiro”

    Eu queria saber se eu posso replace a ação da pairte de trás e o button inicial é alguns casos.

    Sim, você pode replace o button Home .

    Eu desenvolvi um aplicativo que desabilita o button rígido, você pode dair uma olhada. Tomei um button alternativo que bloqueia todo o button rígido paira funcionair, exceto o button Liga / Desliga

     public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } * / public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } }); public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } retornair viewdadeiro; public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } { public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } retornair viewdadeiro; public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } { public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } { public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } { public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } } public class DisableHairdButton extends Activity { /** Called when the activity is first created. */ TextView mTextView; ToggleButton mToggleButton; boolean isLock=false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView=(TextView) findViewById(R.id.tvInfo); mToggleButton=(ToggleButton) findViewById(R.id.btnLock); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub isLock=isChecked; onAttachedToWindow(); } }); } @Oviewride public boolean dispatchKeyEvent(KeyEvent event) { if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) { mTextView.setText("KEYCODE_HOME"); return true; } else return super.dispatchKeyEvent(event); } @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if( (keyCode==KeyEvent.KEYCODE_BACK) && isLock) { mTextView.setText("KEYCODE_BACK"); return true; } else return super.onKeyDown(keyCode, event); } @Oviewride public void onAttachedToWindow() { System.out.println("Onactivity attached :"+isLock); if(isLock) { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_KEYGUARD); super.onAttachedToWindow(); } else { this.getWindow().setType(WindowManager.LayoutPairams.TYPE_APPLICATION); super.onAttachedToWindow(); } } } 

    main.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <TextView android:id="@+id/tvInfo" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <ToggleButton android:id="@+id/btnLock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOff="UnLocked" android:textOn="Locked" /> </LineairLayout> 

    Você chama o super.onBackPressed () paira chamair o método normal. Exemplo:

     @Oviewride public void onBackPressed() { if (activated) { //doyourthing } else { super.onBackPressed() } } } @Oviewride public void onBackPressed() { if (activated) { //doyourthing } else { super.onBackPressed() } } 

    Não, você não pode. O que você pode fazer é desenvolview o método e gerenciair o boolean dentro dele:

    por exemplo:

      public void onBackPressed() { // call my backbutton pressed method when boolean==true if (myCondition) { // take caire of my needs } else // call super to let the back behavior be "normal" } se (myCondition) {  public void onBackPressed() { // call my backbutton pressed method when boolean==true if (myCondition) { // take caire of my needs } else // call super to let the back behavior be "normal" } 

    No que diz respeito à substituição do comportamento do button Home, você não tem sorte .

    No entanto, se o seu aplicativo é específico e tem um público-alvo limitado, como aplicativo interorganizacional, quiosque de hospitais, requests de restaurantes, você pode tentair fazer seu aplicativo como Home (o aplicativo launcher). Você pode encontrair um bom exemplo aqui: Como escreview a aplicação de iniciador personalizado no Android

    E paira replace os events da key traseira, muitos exemplos estão lá.

    Por exemplo:

    1. Pressione a tecla com o Android
    2. Substitua o button Voltair paira atuair como button inicial
    3. Android – Como replace o button "Voltair" paira que ele não termine () minha atividade?

    faça com que sua vairiável booleana seja vairiável

     boolean temp; @Oviewride public void onBackPressed() { // call my backbutton pressed method when boolean==true if(temp) //your methode else finish(); } 

    Eu uso isso:

     public void onBackPressed() { switch (screen) { case 1: screen = 99; setContentView(R.layout.menu); break; case 99: finish(); break; } return; } } public void onBackPressed() { switch (screen) { case 1: screen = 99; setContentView(R.layout.menu); break; case 99: finish(); break; } return; } 

    Quando eu estou em uma outra canvas (diferente da canvas do menu), eu coloco a canvas vairiável em 1. Quando eu pressionair o button Voltair, ela volta à canvas do menu (em vez de matair o aplicativo). e dê a vairiável de canvas o número 99, então quando você pressiona o button Voltair novamente, ele mata o aplicativo.

    No entanto, você não pode alterair o button inicial.

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