How to call getBaseContext() on Fragment

13,920

Solution 1

You can use getActivity(), which returns the activity associated with a fragment.
The activity is a context (since Activity extends Context).

But you can use it after the fragment is attached to the activity..

Solution 2

use getActivity().getBaseContext();

Share:
13,920
hectichavana
Author by

hectichavana

Updated on June 05, 2022

Comments

  • hectichavana
    hectichavana about 2 years

    I have this method which can be called from normal Activity:

    getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
    

    The problem is I cannot call getBaseContext() in Fragment, how can I to do that? Or with what do I need to replace the getBaseContext() from a Fragment class?