Android 應用按返回鍵異常退出的問題

2021-09-07 11:32:43 字數 619 閱讀 2899

開發過程中遇到按返回鍵異常退出的問題,log顯示為空指標異常,進一步產看是由於onactivityresult得到的intent為空。

按返回鍵複寫**例如以下:

@override

public void onbackpressed()

檢視activity源**發現onbackpressed的預設實現例如以下:

/** 

* called when the activity has detected the user's press of the back

* key. the default implementation simply finishes the current activity,

* but you can override this to do whatever you want.

*/

public void onbackpressed()

因此假設呼叫了super.onbackpressed()。就呼叫了finish()函式,因此之後的setresult函式根本沒起作用。去掉了super.onbackpressed()之後。異常消失。

android 按兩次返回鍵退出

我們可以在很多應用中都能看到按兩次返回鍵退出 其實這個功能實現很容易,下面就是實現的 把它放到你的程式中你的程式就能按兩次返回鍵退出啦 這個功能是為了避免誤點而把程式 退出了 給你的程式也加上這個簡單實用的功能把 package com.anjoyo.test import android.os.b...

android 按兩次返回鍵退出

我們可以在很多應用中都能看到按兩次返回鍵就退出,其實這個功能實現很容易,下面就是實現的 把它放在人的程式中你的程式就能按兩次返回鍵退出了,這個功能是為了避免誤點而把程式退出了,給我的程式也加上這個簡單的功能吧 定義全域性變數 private long mexittime 方法 public bool...

android按兩次返回鍵退出程式

android按兩次返回鍵退出程式 現在有很多程式都使用按兩次返回鍵退出程式,下面介紹兩種辦法實現按兩次返回鍵退出程式 private long mexittime override public boolean onkeydown int keycode,keyevent event else r...