title: Android Application - Get last fragment for each activity if already loaded
body: <p>I actually have an aplication with multiple activitys (on for each icon of my toolbar), also I would like to have the possibility to show the last fragment of these activitys from the stack if the user already open it before. 
  As you can see in my BaseActivity class below (which I extend for all my activitys), I already add fragments to the stack.</p>
  
  <p>This is my class :</p>
  
  <pre><code>public class BaseActivity extends AppCompatActivity {
  
  private final String TAG = "BaseActivity";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_base);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      return false;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
  
      return super.onOptionsItemSelected(item);
  }
  
  public void setImageLoaderConfig(Context context) {
      DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
              .cacheInMemory(true).cacheOnDisk(true)
              .resetViewBeforeLoading(true)
              .build();
      ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
              .defaultDisplayImageOptions(defaultOptions)
              .build();
      ImageLoader.getInstance().init(config);
  }
  
  public void initToolBar() {
      LinearLayout linearLayout = (LinearLayout) findViewById(R.id.toolbar_layout);
      Toolbar toolbar = (Toolbar) linearLayout.findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      if (toolbar != null) {
          initToolbarOnClickListener();
      }
  }
  
  private void initToolbarOnClickListener() {
  
      (findViewById(R.id.toolbar_relativelayout_news)).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showActivity(ArticlesActivity.class);
          }
      });
      (findViewById(R.id.toolbar_relativelayout_toilettes)).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showActivity(ToilettesActivity.class);
          }
      });
      (findViewById(R.id.toolbar_relativelayout_practice)).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showActivity(PratiquesActivity.class);
          }
      });
      (findViewById(R.id.toolbar_relativelayout_diary)).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showActivity(AgendaActivity.class);
          }
      });
      (findViewById(R.id.toolbar_relativelayout_forum)).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showActivity(ForumActivity.class);
          }
      });
  }
  
  public void updateToolbarIcons(Integer position) {
      ImageView imageViewIcon;
      Integer[] activeDrawableIds = {R.drawable.menu_actu_hover_320, R.drawable.menu_toilette_hover_320,
              R.drawable.menu_pratiques_hover_320, R.drawable.menu_agenda_hover_320, R.drawable.menu_forum_hover_320};
      Integer[] inactiveDrawableIds = {R.drawable.menu_actu_160, R.drawable.menu_toilette_320,
              R.drawable.menu_pratiques_320, R.drawable.menu_agenda_320, R.drawable.menu_forum_320};
      Integer[] imageviewIds = {R.id.toolbar_imageview_news, R.id.toolbar_imageview_bathroom,
              R.id.toolbar_imageview_practice, R.id.toolbar_imageview_diary, R.id.toolbar_imageview_forum};
      for (int i = 0; i &lt; imageviewIds.length; i++) {
          Log.d(TAG, i + " " + imageviewIds[i]);
          imageViewIcon = (ImageView) findViewById(imageviewIds[i]);
          if (i == position) {
              imageViewIcon.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), activeDrawableIds[i]));
          } else {
              imageViewIcon.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), inactiveDrawableIds[i]));
          }
  
      }
      if (AfamiciApp.isConnected()) {
          ImageView imageViewUser = (ImageView) findViewById(R.id.toolbar_imageview_user);
          imageViewUser.setVisibility(View.VISIBLE);
      }
  }
  
  public void showActivity(Class activityClass) {
      Intent intent = new Intent(this, activityClass);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(intent);
  }
  
  public void initIsConnected() {
      if (AfamiciApp.getMail() != null &amp;&amp; AfamiciApp.getPassword() != null) {
          AfamiciApp.setIsConnected(true);
      }
  }
  
  public void showConnexionFragment(Integer layoutId, Integer id) {
      Bundle args = new Bundle();
      args.putInt("id", id);
      args.putInt("containerId", layoutId);
      ConnexionFragment connexionFragment = new ConnexionFragment();
      connexionFragment.setArguments(args);
      getSupportFragmentManager()
              .beginTransaction()
              .replace(layoutId, connexionFragment, null)
              .addToBackStack(null)
              .commit();
  }
  
  public void showCreationCommentaireFragment(Integer layoutId, Integer id, Boolean isFromConnection) {
      if (isFromConnection) {
          getSupportFragmentManager().popBackStack();
      }
      Bundle args = new Bundle();
      args.putInt("id", id);
      CommentaireFragment commentaireFragment = new CommentaireFragment();
      commentaireFragment.setArguments(args);
      getSupportFragmentManager()
              .beginTransaction()
              .replace(layoutId, commentaireFragment, null)
              .addToBackStack(null)
              .commit();
  }
  
  public void showCreationCompteFragment(Integer layoutId, Integer id) {
      Bundle args = new Bundle();
      args.putInt("id", id);
      CreationCompteFragment creationCompteFragment = new CreationCompteFragment();
      creationCompteFragment.setArguments(args);
      getSupportFragmentManager()
              .beginTransaction()
              .replace(layoutId, creationCompteFragment, null)
              .addToBackStack(null)
              .commit();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks in advance for your replys :)</p>