/*
 * Copyright 2016 Philip Cohn-Cort
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.fuzz.emptyhusk.prefab;

import android.app.Activity;
import android.app.Fragment;
import android.app.ListFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.fuzz.emptyhusk.R;

/**
 * @author Philip Cohn-Cort (Fuzz)
 */
public class PlainActivity extends Activity {

    private static final String ARG_FRAGMENT_CLASS = "fragment_class";
    private static final String ARG_FRAGMENT_ARGS = "fragment_args";

    public static Intent request(@NonNull Context origin, @NonNull Class<? extends Fragment> fragClass, @Nullable Bundle fragArgs) {
        Intent intent = new Intent(origin, PlainActivity.class);
        intent.putExtra(ARG_FRAGMENT_CLASS, fragClass);
        intent.putExtra(ARG_FRAGMENT_ARGS, fragArgs);
        return intent;
    }

    @NonNull
    @SuppressWarnings("unchecked")
    protected Class<? extends Fragment> getPrimaryFragmentClass() {
        Class<? extends Fragment> fragmentClass = (Class<? extends Fragment>) getIntent().getSerializableExtra(ARG_FRAGMENT_CLASS);
        if (fragmentClass == null) {
            fragmentClass = ListFragment.class;
        }
        return fragmentClass;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_plain);

        Bundle args = getIntent().getBundleExtra(ARG_FRAGMENT_ARGS);

        Class<? extends Fragment> fragmentClass = getPrimaryFragmentClass();
        Fragment fragment = Fragment.instantiate(this, fragmentClass.getName(), args);

        getFragmentManager()
                .beginTransaction()
                .add(R.id.primaryContent, fragment, fragmentClass.getSimpleName())
                .commit();
    }
}

@@ -2109,24 +2109,111 @@
 ENT_ARGS);%0A%0A
+        if (getFragmentManager().findFragmentById(R.id.primaryContent) == null) %7B%0A%0A    
         Clas
@@ -2285,16 +2285,20 @@
         
+ 
+   
 Fragment
@@ -2377,16 +2377,20 @@
         
+    
 getFragm
@@ -2418,16 +2418,20 @@
         
+    
 .beginTr
@@ -2442,16 +2442,20 @@
 ction()%0A
+    
         
@@ -2545,16 +2545,20 @@
         
+    
 .commit(
@@ -2556,20 +2556,30 @@
  .commit();%0A
+        %7D%0A
     %7D%0A%7D%0A

Make PlainActivity immune to config changes