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 Fragment
can be attached to an Activity
without being added to it's view hierarchy.
If a Fragment
is detached, it's state is maintained and can be re-added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With