Sometimes FragmentManager destroys and re-instantiates Fragment without any notification by framework's behavior.
Important point here is that default Constructor is used to re-instantiate Fragment.
In this case, without saving and restoring run-time state of Fragment, it looses all of it's state.
This is exactly same with Activity.
But, in terms of Activity, user can know and control when the Activity is destroyed and recreated.
So, in case of Activity, this issue is not big problem.
Therefore, followings should be considered to design Fragment.
- use ONLY default constructor. (FragmentManager uses only default constructor.)
- should NOT have any not-parcelable- run-time data.
But, sometimes, Fragment may need to have not-parcelable-run-time data.
In this case, using Activity can be good choice.
That is, let owner Activity have the data and access it by using getActivity() method.
'Domain > Android' 카테고리의 다른 글
Running java on Android shell command line (0) | 2013.06.21 |
---|---|
ADT 22로 upgrade이후 private library link실패 (NoClassDefFoundError) - 단 compile은 성공. (0) | 2013.06.17 |
[Android] One thing to keep in mind when using FragementPagerAdapter (0) | 2012.12.07 |
[Android - ICS] Strange behavior of Android PatternMatcher - used by pathPattern of IntentFilter (0) | 2012.11.16 |
[Android] Status Bar height (0) | 2012.10.26 |