In my Fragment, I want to make a Toast once some data is loaded, like this:
Toast.makeText(getActivity(), R.string.toast_loading_done,
Toast.LENGTH_SHORT).show();
This only makes sense if the Fragment is still attached to the Activity, i.e. the Fragment is visible and getActivity() will not return null.
I could check that with !isDetached() or with isAdded(), right? Here I am wondering what the difference between the two methods is and which one I should preferably use?
A
Fragmentcan be attached to anActivitywithout being added to it's view hierarchy.If a
Fragmentis detached, it's state is maintained and can be re-added.