Back button deletes Fragment in main Activity

Asked

Viewed 35 times

0

Hello, all right? I’m making a server-going Fragment as a sort of menu cards on the initial interface. I made it every time the app opens It creates this interface inside a Constrainslayout, but when I open it and I click back it disappears and only the bottomNavBar and the Constrains goes...

@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();
        }
    }

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");
}

Insert this code into your Fragment and type Ciclo into your logcat, possibly it is being called the onStop method and with that the values in memory are being deleted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.