Why does getActivity() return null in onCreateView() method of fragment?
Asked
Active
Viewed 1,428 times
2
Sergey Glotov
- 19,939
- 11
- 82
- 96
-
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 Answers
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,781
- 3
- 25
- 47
Anupriya
- 1,593
- 3
- 15
- 26
-
1yes , 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