首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

自各儿监听Home键

2012-07-01 
自己监听Home键对Activity而言:@Overridepublic void onAttachedToWindow() {// TODO Auto-generated meth

自己监听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);

热点排行