i don't know if behavior normal because suppose call finish() stop activity being re-created.
here excerpt of activity class:
public class myactivity extends fragmentactivity { private retainfragment retainfragment; @override protected void oncreate(bundle savedinstancestate) { ...... retainfragment = getsupportfragmentmanager().findfragmentbytag("retainfragment"); if(retainfragment == null) { retainfragment = new retainfragment(); getsupportfragmentmanager().begintransaction().add(retainfragment, "retainfragment").commitallowingstateloss(); } if(retainfragment.isfinish) { log.v("myactivity", "isfinish == true"); this.finish(); } } // on-click event handler finish button public void onfinishclicked(view view) { retainfragment.isfinish = true; this.finish(); } private class retainfragment extends fragment { private boolean isfinish = false; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setretaininstance(true); } } }
the activity persistent(i store other persistent variables in retainfragment didn't show them) , closed after user has clicked finish button, @ point onfinishclicked(view) called, , activity should finished system. don't anticipate recreated system after coincident screen rotation. happens , handle calling finish() again within oncreate() method. however, looks pretty ugly here because finished activity supposed dead forever , have explicitly handle it. :( there misunderstanding of activity lifecycle or retain fragment on part?
this standard android behavior. take @ paragraph of android documentation.
unless specify otherwise, configuration change (such change in screen orientation, language, input devices, etc) cause current activity destroyed, going through normal activity lifecycle process of onpause(), onstop(), , ondestroy() appropriate. if activity had been in foreground or visible user, once ondestroy() called in instance new instance of activity created, whatever savedinstancestate previous instance had generated onsaveinstancestate(bundle).
to avoid this, can set android:configchanges attribute in manifest. types of configuration changes handle there, receive call current activity's onconfigurationchanged(configuration) method instead of being restarted. if configuration change involves not handle, however, activity still restarted , onconfigurationchanged(configuration) not called.
Comments
Post a Comment