Application crashes when user presses Back Button
Good day all, First of all, maybe i went about this the wrong way in the first pla开发者_如何学编程ce. Situation is, i have a listview that when an item is clicked, it creates an intent and calls startActivityForResult() to another activity, to be able to edit the entries in the row. and that other activity after editing the required values, returns back to the calling activity, when the user clicks on a save button. The activity then uses the row Id to update the item.My problem now is that, if the user presses the BACK button instead, the application crashes. i have been looking around and see solutions like using Shared Preferences or onSavedInstanceState(), but i don't know where exactly i should be putting the code? Any help as usual, will be greatly appreciated. Thank you.
p.s: when i look at logcat, its gives a NullPointerException for this line in onActivityResult.
Bundle result = data.getExtras();
If you are assuming you will have a result on the parent thread if the user quits the activity via Back then that is most likely the issue. Try testing if result is null before attempting to use it.
精彩评论