I\'m trying to change the activity title from a fragment (in this case, it\'s an android.support.v4.app.Fragment
). To this end, I save the activity in an attrib
Nowadays you can call requiredActivity()
too that return FragmentActivity
object and if fragment doesn't come from an Activity, method throws a IllegalStateException
You can access the Activity in a Fragment using getActivity()
. It can be called safely as soon as onActivityCreated()
was called on the Fragment. Before that, it might not be there or might not have been fully initialized yet.
If your thread starts before that, just note the fact somewhere in your Fragment and only change the title after onActivityCreated
was called.