{"id":368,"date":"2015-02-03T11:09:26","date_gmt":"2015-02-03T03:09:26","guid":{"rendered":"http:\/\/www.linangran.com\/?p=368"},"modified":"2015-02-08T12:25:40","modified_gmt":"2015-02-08T04:25:40","slug":"fragments-savedinstancestate-is-always-null","status":"publish","type":"post","link":"https:\/\/www.linangran.com\/?p=368","title":{"rendered":"Fragment&#8217;s savedInstanceState is always null."},"content":{"rendered":"<p>First of all, only fragment killed by system will call\u00a0<em>onSaveInstanceState()<\/em> function because of reasons like OOM. Thus, fragment killed by activity&#8217;s <em>finish()<\/em> will not call\u00a0<em>onSaveInstanceState()<\/em>. In this situation, it&#8217;s better to preserve the state in <em>onPause()<\/em>.<\/p>\n<p>Secondly, in <em>onSaveInstanceState()<\/em>, one must call <em>super<\/em>.<em>onSaveInstanceState()<\/em> at the <strong>end<\/strong> of the implemented function.<\/p>\n<p>Thirdly, the fragment should have an TAG or ID associated with it. The best practice is to declare tag in xml or when dynamically adding fragment, use the <em>add()<\/em> function with <em>tag<\/em> argument.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First of all, only fragment killed by system will call\u00a0onSaveInstanceState() function because of reasons like OOM. Thus, fragment killed by activity&#8217;s finish() will not call\u00a0onSaveInstanceState(). In this situation, it&#8217;s better to preserve the state in onPause(). Secondly, in onSaveInstanceState(), one must call super.onSaveInstanceState() at the end of the implemented function. Thirdly, the fragment should have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":1,"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}