java - Why do I sometimes get a stack trace when hiding a fragment? -


i have fragment has inner fragments.

public void hideinnerfragment(string fr_tag) {     fragmenttransaction childtransaction = getchildfragmentmanager().begintransaction();     myinnerfragment inner = (myinnerfragment)   getchildfragmentmanager().findfragmentbytag(fr_tag);     if(inner != null) {         childtransaction.hide(inner);         childtransaction.commit();       }   }   

works fine. have seen times in logs stacktrace following:

java.lang.illegalstateexception: can not perform action after onsaveinstancestate @ android.support.v4.app.fragmentmanagerimpl.checkstateloss(fragmentmanager.java:1377) @ android.support.v4.app.fragmentmanagerimpl.enqueueaction(fragmentmanager.java:1395) @ android.support.v4.app.backstackrecord.commitinternal(backstackrecord.java:637) @ android.support.v4.app.backstackrecord.commit(backstackrecord.java:616) @ com.test.myparentfragment.hideinnerfragment    

why one? haven't figured out when happens.

update:
in case helps/matters:
when fragment created start async task long running operation , depending upon result call hide of inner fragment.

i guessing calling method "hideinnerfragment" async task or called after onpause() has been called.

i had similar problem in last app , solved having public static boolean in hostactivity.

public hostactivity extends activity(){      public static boolean visible = false; // set false;    public void onresume(){      visible = true;  }   public void onpause(){      visible = false;  }  } 

then in fragment

public void hideinnerfragment(string fr_tag)  {    if(hostactivity.visible)   {        fragmenttransaction childtransaction = getchildfragmentmanager().begintransaction();         myinnerfragment inner = (myinnerfragment)   getchildfragmentmanager().findfragmentbytag(fr_tag);         if(inner != null) {          childtransaction.hide(inner);          childtransaction.commit();        }   } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

excel - I can't get the attachement of the email PHP -

node.js - Express and Redis - If session exists for this user, don't allow access -