It turns out there is a getParentFragment() method introduced to cater to nested fragments. It is available on android.app.Fragment
from API 17, but can be used on older versions using android.support.v4.app.Fragment
.
I can't believe I overlooked this API!
EDIT:
I came across this gist that makes this process of figuring out the parent component (whether Fragment
or Activity
) easy, elegant and safe!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…