Android IllegalStateException: Fragment already active when calling notifyDataSetChanged -


i'm new android, , looks there still things missing in understanding of activity lifecycle. have tabbed application created fragmentactivity. custom viewpager managing presentation of tabs , in 1 of tabs want simple drill-down ability use hardware "back" button go level previous view.

i implemented drill-down substituting appropriate fragment tab checking value of flag (which determines in drill down are):

public class sectionspageradapter extends fragmentstatepageradapter {  @override public fragment getitem(int position) {    fragment fragment;      switch (position) {    case 0 :       if (stateflag == 0) fragment = (fragment) new initialfragment();      else fragment = (fragment) new finalresultsfragment();      break;    case 1:       fragment = (fragment) new secondtabfragment();      break;     default:      fragment = (fragment) new thirdtabfragment();      break;   }    return fragment; } 

to go "previous" fragment this:

@override public void onbackpressed() {     int p = mviewpager.getcurrentitem();      switch (p) {     case 0:         if (stateflag == 0)) {             super.onbackpressed();         } else {             stateflag = 0;             mviewpager.getadapter().notifydatasetchanged();             mviewpager.setcurrentitem(0);         }         break;     default:         super.onbackpressed();         break;     }  } 

this works fine, until try changing orientation. fragments come change successfully, when try pressing button while in finalresultsfragment state,

illegalstateexception: fragment active e/androidruntime(1094):     @ android.support.v4.view.pageradapter.notifydatasetchanged(pageradapter.java:276) 

why change in orientation breaking particular part of code?

edit:

so if open app, first tab active, press button loads different fragment in tab, press button - it's , first fragment loaded, expected.

but if open app, first tab active, press button loads different fragment in tab, rotate screen, fragment re-loaded fine, press button - crash!

edit:

here complete error log: http://pastebin.com/esdtstsm


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -