Android開發(fā)筆記之:返回鍵的復寫onBackPressed()介紹
更新時間:2013年05月28日 11:11:15 作者:
本篇文章是對Android中返回鍵的復寫onBackPressed()進行了詳細的分析介紹,需要的朋友參考下
在android開發(fā)中,當不滿足觸發(fā)條件就按返回鍵的時候,就要對此進行檢測。尤其是當前Activity需要往前一個Activity傳送消息時。即Activity1跳轉(zhuǎn)到Activity3如果采用的是startActivityForResult這種方式,如果不重寫返回鍵,程序不知道要返回給Activity1什么內(nèi)容就會報錯。因此,必須對Activity3的返回按鍵重寫,這里讓他傳一個“ERROR”信息:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent backIntent = new Intent(Activity3.this, Activity1.class);
Bundle bundle = new Bundle();
if(!clickOk)
bundle.putString("send", "ERROR");
backIntent.putExtras(bundle);
Activity3.this.setResult(1, backIntent);
Activity3.this.finish();
//super.onBackPressed();
}
復制代碼 代碼如下:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent backIntent = new Intent(Activity3.this, Activity1.class);
Bundle bundle = new Bundle();
if(!clickOk)
bundle.putString("send", "ERROR");
backIntent.putExtras(bundle);
Activity3.this.setResult(1, backIntent);
Activity3.this.finish();
//super.onBackPressed();
}
相關(guān)文章
Android使用Service實現(xiàn)簡單音樂播放實例
這篇文章主要為大家詳細介紹了Android使用Service實現(xiàn)簡單音樂播放實例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05
快速解決fragment中onActivityResult不調(diào)用的問題
下面小編就為大家?guī)硪黄焖俳鉀Qfragment中onActivityResult不調(diào)用的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04
如何利用Flutter實現(xiàn)酷狗流暢Tabbar效果
這篇文章主要給大家介紹了關(guān)于如何利用Flutter實現(xiàn)酷狗流暢Tabbar效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2022-02-02
Android實現(xiàn)九宮格(GridView中各項平分空間)的方法
這篇文章主要介紹了Android實現(xiàn)九宮格(GridView中各項平分空間)的方法,涉及Android針對GridView操作的相關(guān)技巧,需要的朋友可以參考下2015-06-06

