您好我正在开发我正在使用actionbar Sherlock的Android应用程序。我的应用程序包含一个主要活动,其中3个片段包含3个标签。我的第一个选项卡显示列表视图,如果我点击列表项,它会打开新的详细活动。所以当我关闭细节活动时我想要自动切换另一个选项卡。
所以我的代码看起来像
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(getActivity(), CardDetails1.class);
startActivityForResult(intent, 7);
}
我正在做的活动结果:
@Override @SuppressLint("NewApi")
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 7)
{
getActivity().getActionBar().setSelectedNavigationItem(2);
}
}
当我点击后面的BUt时,它会给我以下错误
08-08 10:36:58.149: E/AndroidRuntime(7351): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131079, result=0, data=null} to activity {com.example.sample/com.ecample.sample.LeftAndRightActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
08-08 10:36:58.149: E/AndroidRuntime(7351): at android.app.ActivityThread.deliverResults(ActivityThread.java:3398)
08-08 10:36:58.149: E/AndroidRuntime(7351): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3448)
08-08 10:36:58.149: E/AndroidRuntime(7351): at android.app.ActivityThread.access$1100(ActivityThread.java:139)
08-08 10:36:58.149: E/AndroidRuntime(7351): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
08-08 10:36:58.149: E/AndroidRuntime(7351): at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 10:36:58.149: E/AndroidRuntime(7351): at android.os.Looper.loop(Looper.java:156)
任何人都有解决方案。我需要帮助。谢谢。
答案 0 :(得分:0)
使用:transaction.commitAllowingStateLoss();
添加或执行导致FragmentTransaction
的{{1}}。