After you come back to your view, your activity may not be created yet when onCreateView()
is called.
What you should do is to move all the code that depends on the activity to onActivityCreated() method. According to the documentation this method is:
Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.
You can then use your activity.
Also, there's no need to pass the activity to the fragment, as you can always get it using getActivity()
method. Not passing your activity will also limit your chance of creating a memory leak.