android - After replacing Fragment, Activity still detects Fragment is visible -
i have 1 activity hosts many fragments. in fragment a, adding dialog when user presses button ask if sure if want leave fragment. added code in activity's onbackpressed control this:
@override public void onbackpressed() {     fragmenta fragmenta = (fragmenta) getsupportfragmentmanager().findfragmentbytag("fragmenta");      if (fragmenta != null && fragmenta.isvisible()) {         fragmenta.showexitdialog();         return;     }     else { super.onbackpressed(); } } and dialog works in fragment a, when leaves fragment , goes fragment b (same activity) code:
getactivity().getsupportfragmentmanager().begintransaction().replace(r.id.container,                  fragmentb.newinstance(), "fragmentb").commit(); and press button in fragment b, shows same exit dialog again.
thus, code, saying fragmenta not null , still visible after did replace function. 
why fragment still visible when replaced fragment b?
 
 
  
Comments
Post a Comment