我正在使用Fragment
使用Activity
开始新startActivityForResult()
,我在(Bundle)
()方法中获得结果onActivityResult
。{在onActivityResult
()之前调用了{1}}()。我想确保正确保存/保存onResume
,以便在Bundle
Fragment's
被调用时,我获取保存/保存的结果以执行进一步操作。
实现这一目标的不同方法有哪些。我尝试使用getArguments()/ setArguments(),但这似乎不是实现此目的的正确方法。
答案 0 :(得分:2)
试试这个
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
mResultBundle = data.getExtras(); //mResultBundle is in fragment
//scope
}
}
}
@Override
protected void onResume(){
super.onResume();
if(mResultBundle != null){
// process saved bundle from activity result here
// don't forget to set it back to null once you are done
mResultBundle = null;
}
}