How to get application object into fragment class

Rakesh Gourineni picture Rakesh Gourineni · Jul 20, 2012 · Viewed 36.2k times · Source

I am changing my android mobile app to support both tablets and mobile phone. For this I am changing my activity class into fragment. In my activity class I have an instance of my application class created as below:

appCtx = (UnityMobileApp) getApplication();

Where UnityMobileApp is my Application class.

Now I want to create the same instance in my fragment class. Can you guys please help me solve this?

Answer

biegleux picture biegleux · Jul 20, 2012

Use appCtx = (UnityMobileApp) getActivity().getApplication(); in your fragment.