android - Shared element return / reenter transition broken after configuration change -


i have activity , b, shared element transition, works fine, until:

  1. transition -> b in portrait orientation
  2. in b, change orientation landscape
  3. hit back
  4. the shared element doesn't know return, floats there stupidly in place until reenter transition finishes, disappears

this looks awkward. understand because shared element connected portrait landscape of a, , not landscape one. can done alleviate pain?

i checked google play store app exact same scenario described above, selecting app list, going list after orientation change. seems pop list without animation, lot better, there's @ least no broken transition , floating elements. way achieve behavior?


update: make clear, following scenario works perfectly fine:

  1. transition -> b in portrait orientation
  2. in b, change orientation landscape
  3. change orientation again, portrait
  4. hit back
  5. the shared element job , returns a

so not case view doesn't survive configuration changes.

i'm answering own question, @ least part regarding how previous activity without transition after orientation change.

  1. in activity oncreate(), create or restore retained fragment holding original screen orientation
  2. override onbackpressed() , check if current screen orientation same original. if not, finish activity (no transition).

    private state state;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     initstate(); }  private void initstate() {     string tag = "state";     fragmentmanager fm = getfragmentmanager();      // find or create fragment     this.state = (state) fm.findfragmentbytag(tag);     if (this.state == null) {         this.state = new state();         fm.begintransaction().add(this.state, tag).commit();          // store original screen orientation         this.state.originalorientation = getresources().getconfiguration().orientation;     } }  @override public void onbackpressed() {     // shared element broken     if (getresources().getconfiguration().orientation != state.originalorientation) {         // no transition         finish();      } else {         // default behavior         super.onbackpressed();     } }  public static class state extends fragment {     private int originalorientation;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setretaininstance(true);     } } 

it better fix original problem, no transition still better broken one.


Comments