Instantiate Fragments only once with navigationBotton

0

Good evening, I need a force, I'm implementing a navigation bot to navigate fragments, however in one of the fragments there will be a counter and when I navigate through the screens the counter will restart.

Is there a way to save the status of the fragment so the counter stays?

Thank you in advance

  mBottomNavigationView.setOnNavigationItemSelectedListener
            (new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected( MenuItem item) {
                    Fragment selectedFragment = null;
                    switch (item.getItemId()) {
                        case R.id.action_item1:
                            mTitle_Toolbar.setText(getString(R.string.toobar_call_activity));
                            //mToolbar.setLogo(R.mipmap.ic_reorder_white_24dp);
                            //selectedFragment = CalledFragment.newInstance();
                            fragmentManager(CalledFragment.newInstance(),getString(R.string.toobar_call_activity) );
                            break;
                        case R.id.action_item2:
                            mTitle_Toolbar.setText(getString(R.string.toobar_project_activity));
                            //mToolbar.setLogo(R.mipmap.ic_assignment_turned_in_white_24dp);
                            selectedFragment = ProjectsFragment.newInstance();
                            fragmentManager(Profilefragment.newInstance(),getString(R.string.toobar_project_activity) );
                            break;
                        case R.id.action_item3:
                            mTitle_Toolbar.setText(getString(R.string.toobar_profile_activity));
                            //mToolbar.setLogo(R.mipmap.ic_account_box_white_24dp);
                            //selectedFragment = Profilefragment.newInstance();
                            fragmentManager(Profilefragment.newInstance(), getString(R.string.toobar_profile_activity));
                            break;
                    }
                    //fragmentManager(selectedFragment);
                    return true;
                }
            });
    mBottomNavigationView.setSelectedItemId(R.id.action_item1);
}



public void fragmentManager(Fragment mFragment, String tag){
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.frame_layout, mFragment);
    transaction.addToBackStack(null);
    transaction.commit();

}
    
asked by anonymous 22.09.2017 / 00:22

0 answers