Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call getBaseContext() on Fragment

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?

like image 468
hectichavana Avatar asked Nov 16 '12 13:11

hectichavana


Video Answer


2 Answers

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..

like image 126
Nermeen Avatar answered Sep 18 '22 15:09

Nermeen


use getActivity().getBaseContext();

like image 41
ingyesid Avatar answered Sep 16 '22 15:09

ingyesid