The context from a Fragment
can be obtained through getActivity()
.
getActivity()
, Returns the Activity associated with the Fragment.
Activity is a Context (Activity extends from Context) .
I have a fragment that calls an activity, when closing the activity and
back to my fragment the context is null
I think the problem is the variable that you have as Context, maybe you use the context of the activity that you opened and then closed, I suggest you get the context within the Fragmente using getActivity()
.
By obtaining the context of this form you will get the context of the Activity
associated with the Fragment
whose value would not be null.