[英]onActivityResult changing my current Fragment
I am currently having a seemingly odd bug with an application I am writing, this only seems to happen, thus far, on a Samsung S4. 我目前在编写一个应用程序时遇到一个看似奇怪的错误,到目前为止,这似乎只发生在Samsung S4上。 It does not happen on an S4 Mini, S5, S6 and Hisense HS-U980.
在S4 Mini,S5,S6和海信HS-U980上不会发生。 Which is why I am so confused.
这就是为什么我如此困惑。
I am using a Sliding Drawer system, each menu item changes the current fragment in the Activities container. 我使用的是滑动抽屉系统,每个菜单项都会更改“活动”容器中的当前片段。
This is an example of what happens, I go to Fragment B, I click a button to load an Image using startActivityForResult: 这是发生的情况的示例,我转到片段B,单击一个按钮以使用startActivityForResult加载图像:
i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, 1);
break;
onActivityResult is then called: 然后调用onActivityResult:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
if(data.getData() != null) {
image = ImageTools.copyImage(getActivity(), data.getData());
int orientation = ImageTools.getOrientationEXIF(getActivity(), image);
setImage(orientation);
saveData();
refreshView();
}
}
}
}
And then instead of returning to Fragment B, I go back to the main Fragment, Fragment A. It also does this with another startActivityForResult call in Fragment C, it too returns to Fragment A. 然后,不返回片段B,而是返回到主要片段FragmentA。它也通过片段C中的另一个startActivityForResult调用来执行此操作,它也返回到片段A。
On the Phones I mentioned where it doesn't do this, it returned to the fragment where the call was made. 在电话中,我提到了不执行此操作的电话,它返回了进行呼叫的片段。
Please let me know if you need some more information/code, I am not sure why this seems to happen only on one device. 如果您需要更多信息/代码,请告诉我,我不确定为什么这似乎仅在一台设备上发生。
Try this: 尝试这个:
With a device that your code works go to Settings / Developer options and activate the option Don't keep activities. 对于您的代码有效的设备,请转到“设置” /“开发人员”选项,然后激活“不保留活动”选项。
Then try to do the same and the problem should also occur in this device. 然后尝试执行相同操作,并且此设备中也应该出现问题。
I think you have the code for adding the Fragment A in some method that is executed again when the activity is recreated. 我认为您具有用于在重新创建活动时再次执行的某种方法中添加Fragment A的代码。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.