首先,我要提一下,我已经搜索了很长时间的这个错误,并且找到了很多解决方案,但是没有一个解决方案帮助我。
我的问题是我在屏幕的上半部分有一个幻灯片(用水平滚动视图实现),下半部分有一个gridview。当我第一次启动应用程序时,点击播放异常的幻灯片: IllegalStateException:在onSaveInstanceState之后无法执行此操作
LogCat告诉我,当fragmentmanager尝试使用“commit()”方法更改片段时,会发生这种情况。我已经尝试了“commitAllowingStateLoss()” - 方法,但后来我得到了一个“Activity已被销毁”-Exception - 也在同一行,片段管理器尝试提交更改。
相反,如果我单击gridview中的一个gridtile,片段管理器会切换内容,而不会出现任何问题。这在我看来是一种奇怪的行为,因为幻灯片和gridview是同一片段的一部分,片段管理器可以切换内容而不是一次?
任何人都可以解释这种行为并帮助我理解我的错误吗?下面是一些代码:
switchContent方法的一部分,用于切换片段:
ft.replace(R.id.fragment_container, fragment, tag);
fragment.setCustomTag(tag);
ft.commit();
单击手势检测器检测到幻灯片显示:
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Point position = convertPositions();
Bundle b = new Bundle();
b.putLong(Constants.BUNDLE_ID, getCurrentId());
b.putInt(Constants.BUNDLE_POSITON, position.y);
((NavigationActivity) getContext()).switchContent(
Constants.TAG_FRAGMENT, b, false);
return true;
}
通过正常的onClickListener检测并点击gridview的图块:
gridview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(android.widget.AdapterView<?> arg0, View v,
int position, long arg3) {
Bundle b = new Bundle();
b.putLong(Constants.BUNDLE_ID, id);
b.putInt(Constants.BUNDLE_R_POSITION, position);
context.switchContent(Constants.TAG_FRAGMENT2, b, refresh);
}});
提前致谢;)