Back button deletes fragment in main activity

0

Hello, how are you? I'm doing a fragment that goes server as a sort of menu cards in the initial interface. I have made it every time the app opens It creates this interface inside a ConstrainsLayout, however when I open it and click back it disappears and only gets the bottomNavBar and the Constrains empty ...

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_nav_bar);

        cardButtonID = (CardView) findViewById(R.id.cardButtonID);
        animationMenu();

//chamando a UI
        if (savedInstanceState == null){
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.add(R.id.mainViewId, new MainPageFragment());
            fragmentTransaction.commit();
        }
    }
    
asked by anonymous 23.07.2018 / 18:42

1 answer

0

Make sure your fragment is calling the onStop method.

@Override
public void onResume() {
    super.onResume();
    Log.e("Ciclo", "Activity: Metodo onResume() chamado");
}

@Override
public void onPause() {
    super.onPause();
    Log.e("Ciclo", "Activity: Metodo onPause() chamado");
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Log.e("Ciclo", "Activity: Metodo onSavedInstanceState() chamado");
}

@Override
public void onStop() {
    super.onStop();
    Log.e("Ciclo", "Activity: Metodo onStop() chamado");
}

@Override
public void onDestroy() {
    super.onDestroy();
    Log.e("Ciclo", "Activity: Metodo onDestroy() chamado");
}

Enter this code in your fragment and type Cycle in your logcat, possibly the onStop method is being called and thus the values in memory are being deleted.

    
11.08.2018 / 02:57