2

Why does getActivity() return null in onCreateView() method of fragment?

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
  • Code and exception stacktrace from logcat, please. http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – laalto Sep 17 '14 at 06:52
  • I have solved my problem by puting my task on onactivitycreated method. –  Sep 18 '14 at 18:02

1 Answers1

3

In this case getActivity() is returning null because getActivity() gets the activity reference once the onActivityCreated() method of activity is called and this method is called after onCreateView() of fragment.

ekostadinov
  • 6,880
  • 3
  • 29
  • 47
Anupriya
  • 1,663
  • 3
  • 17
  • 28
  • 1
    yes , we could not call getActivity() method to use the reference of Activity inside fragment until the fragment not attached or created . – Ashish Saini Sep 22 '14 at 09:42