Android: When calling and closing an activity from a fragment, the fragment context is null?

1

Good morning.

I have a fragment that calls an activity, when I close the activity and return to my fragment the context is zero. How can I solve this situation?

This is what I find when I close the activity, I do not have access to the context or nothing, everything is null

    
asked by devjav 29.11.2016 в 21:01
source

1 answer

3

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.

    
answered by 29.11.2016 в 21:33