自己监听Home键
对Activity而言:
@Override public void onAttachedToWindow() { // TODO Auto-generated method stub this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (KeyEvent.KEYCODE_BACK == keyCode) { if (lThread != null) { flag = false; lThread = null; } if (tThread != null) { flag = false; tThread = null; } Log.d(TAG, "BACK--------delete the file update.zip---------"); mFileUtils.delete(flash_path, FileUtils.FW_NAME); android.os.Process.killProcess(android.os.Process.myPid()); } if (KeyEvent.KEYCODE_HOME == keyCode) { if (lThread != null) { flag = false; lThread = null; } if (tThread != null) { flag = false; tThread = null; } Log.d(TAG, "HOME--------delete the file update.zip---------"); mFileUtils.delete(flash_path, FileUtils.FW_NAME); Intent i = new Intent(); i.setClassName("net.flync.pc2.tv", "net.flync.pc2.tv.activity.HomeActivity"); startActivity(i); this.finish(); } return super.onKeyDown(keyCode, event); }2.对Dialog而言:
mypDialog.show(); // ignore home mypDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);