문제

Which lifecycle method of the Fragment class is the best to call the execute() method on a AsyncTask onCreate(), onAttach() or onActivityCreated()? I want to load data into TextViews on the Fragment's first time it is shown.

도움이 되었습니까?

해결책

I would use onCreate() as you only want it the first time and not after resuming. Look at the the Android documentation on Fragments though to make sure you understand fully. It has a nice fragment lifecycle image which I have put below for reference.

Fragment lifecycle - from Android Documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top