I'm studying MVP.
I have and activity with nav menu and I change fragments from menu like this:
switch (id) {
case R.id.nav_status:
fragmentManager.beginTransaction().replace(R.id.fr_main, mAppProductFragment).commit();
Log.d(TAG, "Выбрано меню статус");
break;
case R.id.nav_schemas:
AppRedirectFragment schemasFragment = new AppRedirectFragment();
fragmentManager.beginTransaction().replace(R.id.fr_main, schemasFragment).commit();
Log.d(TAG, "Выбрано меню переадресация");
break;
}
The problem is that when I change the fragment, my previous fragment is destroyed. It calls the following callbacks:
D/AppProductPresenter: onStopDetouchView()
D/AppProductFragment: onDestroyView
D/AppProductFragment: onDestroy()
It loses its reference to the presenter and also dsipose all retrofit requests.
mPresenter.onDestroyView();
, so all my network operations are destroyd. But Id like to run them in backgroud. But its disposed.
public void onDestroy() {
super.onDestroy();
mPresenter.onDestroyView();
}
So how can change fragments without calling onDestroy being called? I read that I have to use add
instead of fragmentManager.beginTransaction().replace
So how do it correctly?