GetFragmentManager () inside static inner class

How can I get the getFragmentManager () method inside an inner class that is static?

Why? I am trying to fix a rotation issue in my application and so far it seems like the inner class must be static for the problem to go away, but when the inner class is static I cannot get the getFragmentManager () reference.

I tried to instantiate a Context object using the getActivity () or getApplicationContext () method and then do context.getFragmentManager (), but that doesn't work as getFragmentManager () doesn't want to compile inside a static inner class.

Thank you for your help.

+3


source to share


1 answer


When you need access to an Activity Context method in another class, an easier way to do this is to send Context

as a parameter or directly to the constructor if it's not a static class.



You can also submit an Activity in it , which will allow you to check Activity.isFinishing()

to avoid crashing if the activity is trying to terminate itself.

+1


source







All Articles