In my application, I have a left menu that controls Fragment
transactions in one FragmentView
in my MainActivity
. Above the FragmentView
I have the new PullToRefresh
component that is used in the new GMAIL only being refreshed in only one Fragment
.
I want to stop the refreshing of it if I have replaced this Fragment
with another one.
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new pullToRefreshFragment())
.commit();
I expected that the FragmentManager
stick to the traditional FragmentLifeCycle then, I decided to stop the PullToRefresh
component in onPause
, onDestroy
, onStop
or onDetach()
methods. Unfortunately, Those method never been called on replacing the Fragment
. They only been replace if I have selected the same fragment from the left menu.
@Override
public void onDetach() {
if(mPullToRefreshLayout.isRefreshing()){
mPullToRefreshLayout.setRefreshComplete();
}
super.onDetach();
}
That means that, the FragmentManager
is caching the fragments and does not destroy them unless if I am trying to replace a fragment with another fragment from the same Type.
My question is, What is the fragment lifeCycle in case of replacing or adding a new fragment over another one using FragmentManager
?
Where should I stop my PullToRerfesh component, if I want to stop it when replacing the fragment with another one?