你能帮我解决这个问题吗?我有应用程序的选项卡。每个选项卡都包含自己的片段后端堆栈。当我在用户按下任何标签时尝试清除后堆栈时出现问题。我在调用堆栈活动中onResume()
时尝试清除堆栈。但是这个解决方案会导致以下错误:
12-18 12:41:41.700: E/AndroidRuntime(4136): FATAL EXCEPTION: main
12-18 12:41:41.700: E/AndroidRuntime(4136): java.lang.RuntimeException: Unable to resume activity {cz.anywhere.fio_t/cz.anywhere.fio_t.fragments.stack.MarketStack}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
这是用于反向堆栈的类。
public class MarketStack extends TabFragmentActivity{
final public static String MARKET_MAIN_FRAGMENT_TAG = "main_market_fragment";
final public static String MARKET_SECURITIES_FRAGMENT_TAG = "market_securities_fragment";
final public static String MARKET_DETAIL_FRAGMENT_TAG = "market_detail_fragment";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("MarketStack", "onCreate");
if(savedInstanceState == null){
addFragmentToStack(new MarketFragment(), MARKET_MAIN_FRAGMENT_TAG);
}
}
@Override
protected void onResume() {
super.onResume();
Log.i("MarketStack", "onResume");
}
}
父母班。在onResume()
方法中发生了错误。
public class TabFragmentActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_in_tab);
Log.i("TabFragmentActivity", "onCreate");
}
public void addFragmentToStack(Fragment newFragment, String fragmentTag) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.replace(R.id.content, newFragment, fragmentTag);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
@Override
public void onBackPressed() {
Log.i("TabFragmentActivity", "onBackPressed");
FragmentManager manager = getSupportFragmentManager();
if (manager.getBackStackEntryCount() > 1) {
super.onBackPressed();
} else {
// Otherwise, ask user if he wants to leave :)
//showExitDialog();
super.onBackPressed();
}
}
@Override
protected void onResume() {
super.onResume();
FragmentManager fm = getSupportFragmentManager();
for(int i = 0; i<fm.getBackStackEntryCount()-1; i++){
fm.popBackStack();
}
}
感谢您的建议。