开发者

App crashes on back button / Activities & Intents

开发者 https://www.devze.com 2023-01-03 18:12 出处:网络
I have an android application which starts a new activity Intent startAuthorization = new Intent(AndroidActivity, AuthorizeUser.class);开发者_如何学Go

I have an android application which starts a new activity

Intent startAuthorization = new Intent(AndroidActivity, AuthorizeUser.class);  开发者_如何学Go     
startActivityForResult(startAuthorization,4711);

When that new activity is done (a ok button is clicked) I call

setResult(RESULT_OK, returnResult);
finish();

Which works fine. In case the user doesn't click the okay button but uses the return button of the phone (this arrow pointing around to the left) the application has a force close. I have set a breakpoint on the first line of my method onActivityResult but the debugger never stops there. I have no idea where the issue comes up - how can I find out? Is there a method I have to overwrite to handle this back button?


try this if you don't find any better solution for your problem. overwrite the onKeyDown event to prevent your app from going back when you press back button

public boolean onKeyDown(int keyCode, KeyEvent msg){
    if((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_HOME)
        || (keyCode == KeyEvent.KEYCODE_CALL))
        return false;
    else
        return true;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消