在登錄頁(yè)或者歡迎頁(yè)onCreate方法加入如下代碼:
? if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0)
? ? ? ? {
? ? ? ? ? ? finish();
? ? ? ? ? ? return;
? ? ? ? }
?在主頁(yè)攔截返回鍵泽谨,達(dá)到點(diǎn)擊home鍵效果(不銷毀Aacivity,點(diǎn)擊app圖標(biāo)直接進(jìn)入頁(yè)面)
? ? @Override
? ? public boolean onKeyDown(int keyCode, KeyEvent event) {
? ? ? ? if(keyCode==KeyEvent.KEYCODE_BACK){
? ? ? ? ? ? // 仿返回鍵退出界面,但不銷毀凤藏,程序仍在后臺(tái)運(yùn)行
? ? ? ? ? ? moveTaskToBack(false); // 關(guān)鍵的一行代碼
? ? ? ? ? ? return true;
? ? ? ? }
? ? ? ? return super.onKeyDown(keyCode, event);
? ? }
---------------------
作者:瘋狂D烏牛
來(lái)源:CSDN
原文:https://blog.csdn.net/u010350891/article/details/83415761
版權(quán)聲明:本文為博主原創(chuàng)文章周叮,轉(zhuǎn)載請(qǐng)附上博文鏈接!