Control the back “button” in android

前端 未结 2 717
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 09:20

I want to get the Text data value from Sub-Activity back. And everything is ok. But when the Sub-activity was opened, then I just click back \"button\" on the phone, it thro

2条回答
  •  佛祖请我去吃肉
    2021-01-14 10:14

    I think Nate is correct about the NPE at intent.getExtras().

    You should be checking the value of your result code before you do anything. You also might want to check to make sure intent.hasExtra(SBooksDbAdapter.KEY_TITLE_RAW) before you get that value. So, something like this:

    switch(requestCode){
    case ACTIVITY_SEARCH:
        if (resultCode == RESULT_OK && intent.hasExtra(SBooksDbAdapter.KEY_TITLE_RAW)) {
            title_raw = intent.getStringExtra(SBooksDbAdapter.KEY_TITLE_RAW);
            ... do all that other stuff ...
        }
    }
    

提交回复
热议问题