1

Basically this is the problem I have with orientation concerning sherlocktabs.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_leavetab);


    ActionBar actionBar = getSupportActionBar();

    // Hide Actionbar Title
    actionBar.setDisplayShowTitleEnabled(false);
    View homeIcon = findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home
            : R.id.abs__home);
    ((View) homeIcon.getParent()).setVisibility(View.GONE);
    // Create Actionbar Tabs
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    // Set Tab Icon and Titles
    Tab1 = actionBar.newTab().setText("New Leave");
    Tab2 = actionBar.newTab().setText("My Leaves");
    // Set Tab Listeners
    Tab1.setTabListener(new TabListener(leaveform));
    Tab2.setTabListener(new TabListener(leave));


    // Add tabs to actionbar
    actionBar.addTab(Tab2);
    actionBar.addTab(Tab1);
    // actionBar.addTab(Tab3);      
}
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("tabState", ActionBar.getSelectedTab());
}

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setBackgroundDrawable(
            new ColorDrawable(Color.parseColor("#FF8512")));
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    inflater.inflate(R.menu.leave, menu);
    MenuItem menu1 = menu.findItem(R.id.reload_list);
    menu1.setTitle(name);
    return true;
}

The above fragment activity creates three two tabs - listfragment and a fragment. When I change the orientation of screen to landscape I get a fatal exception like below

FATAL EXCEPTION: main java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1361) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574) at com.actionbarsherlock.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:536) at com.actionbarsherlock.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:912) at com.actionbarsherlock.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:504) at android.view.View.performClick(View.java:2485) at android.view.View$PerformClick.run(View.java:9080) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3687) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) at dalvik.system.NativeStart.main(Native Method)

This works just fine in devices with api >11 but crashes in devices with api <11. I am quite new to fragments and thereby wondering about what the problem might be. Is is something concerning the saved state of activity?

2 Answers2

0

"Fragments require API Level 11 or greater"

From: http://developer.android.com/guide/components/fragments.html

wvdz
  • 16,251
  • 4
  • 53
  • 90
  • That's why I am using actionbarSherlock which supports pre-3.0 http://stackoverflow.com/questions/5349170/how-to-implement-the-action-bar-in-api-levels-less-than-11 – Rigorous implementation Nov 08 '13 at 00:53
0

For fragment, use .commitAllowingStateLoss() method instead of .commit(); Or try commenting out //super.onSaveInstanceState(outState); and see if that helps

ToolFan
  • 650
  • 7
  • 12