I am not exactly sure if this is the cause of your problem but your 
fragment creation code is flawed. When you use *setRetainInstance(true)* you 
don't need to create the fragment every time the activity is created. Also, 
I don't know why you check for saveInstance to be null. When the phone is 
rotated you should just retrieve the existing fragment instance from the 
FragmentManager. I use something like below in mu base Activity:

    protected Fragment addFragment( Class<?> clss ) {
        String tag = clss.getSimpleName();
        FragmentManager fm = getSupportFragmentManager();
        Fragment f = fm.findFragmentByTag( tag );
        if ( f == null ) {
            f = Fragment.instantiate( this, clss.getName() );
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.add( R.id.fragment_container, f, tag );
        ft.commit();
        return f;
    }


And then in onCreate() of my Activity I simply call:

MyFragment f = addFragment( MyFragment.class ); 

This means that a Fragment instance is created the first time the Activity 
is created but on any subsequent rotations, the existing Fragment instance 
is retrieved from the FragmentManager is attached to the activity.

Your code creates a new Fragment instance every time the device is rotated, 
which may lead to other issues like Fragment instances with no attached 
Activity.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to