Stop fragment from initializing anytime Activity switches Android
<p>Good day, i have 2 Activities which have their own set of fragments. now anytime i switch between this Activities through intents, it always re-intializes the fragments. I have extended the application class and used it in the activity so that certain operations don't run from OnCreate() again. but no luck. any ideas or is it just the way the life cycle works. i notice OnStop() is being called on the fragments. Thanks for the feedback in advance.</p>

<p>code from one Activity onCreate:</p>

<pre><code>if(savedInstanceState == null){ 
    /*static method from extending application class (MYApp)so this does not run again in oncreate of activity*/
            if(!MYApp.getBoolean()){  /


              dashboardfragment = new DashBoardFragment();
              ft.add(R.id.fragment_container, dashboardfragment, DASHBOARD_FRAG_TAG);  
              ft.addToBackStack(null);
              ft.commit();
              MYApp.setBoolean(true);

            } else {

                showDashboardFragment();

            }
</code></pre>

<p>and showDashboardFragment():</p>

<pre><code>public void showDashboardFragment(){

      FragmentTransaction ft = fragmanager.beginTransaction();

      if(fragmanager.findFragmentByTag(DASHBOARD_FRAG_TAG) != null ){               
          ft.replace(R.id.fragment_container, dashboardfragment, DASHBOARD_FRAG_TAG);
          ft.commit();
      } 

      else {     
          dashboardfragment = new DashBoardFragment();
          ft.replace(R.id.fragment_container, dashboardfragment, DASHBOARD_FRAG_TAG);                        
          ft.addToBackStack(null);
          ft.commit();
      } 
    }
</code></pre>
