I have given toolbar for each fragment in my app.
Following is code in the fragment to set toolbar. setToolbar
is a method in Activity
which is called from fragment using the interface.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Toolbar toolbar = view.findViewById(R.id.toolbar);
if (mListener != null) {
mListener.setToolbar(toolbar);
}
}
Now since I am not removing toolbar when the fragment is destroyed it is causing a memory leak. I want to know where should I remove the toolbar fragment and how.
Any idea where and how should I release toolbar which is in the fragment?
As per my previously asked question Can I have toolbar for each fragment separately. How to handle navigation drawer I was told I can have a toolbar in each fragment but now I am facing memory leak.