android - Replaced fragment still visible -


when start app runs asynctask load , in onpostexecute, setcontentview new layout add fragment 2 buttons offering 2 modes add fragmenttransaction. after 1 of 2 modes clicked, replaces fragment yet fragmenttransaction using replace method.

if app crashes returns first screen, loading 2 buttons offering 2 modes. in case if either mode selected, second fragment loaded background transparent showing 2 buttons below , remain clickable. if clicked again replace fragment isn't visible below. weird, can't understand cause this.

i've researched , seen these 2 similar questions, one , two, suggested might because id wrong or have defined fragment in xml. neither of these 2 factors case.

my code shown below:

below replace loading screen.

@override     protected void onpostexecute(void result) {         setcontentview(r.layout.activity_main_screen);         fragmenttransaction transaction = getsupportfragmentmanager()                 .begintransaction();         transaction.add(r.id.fragment_container, new modefragment())                 .commit();             } 

after which, when button clicked pass fragment wish replace current method below:

private void replacecurrentfragment(fragment fragment) {     fragmenttransaction transaction = getsupportfragmentmanager()             .begintransaction();     transaction.replace(r.id.fragment_container, fragment)             .settransition(fragmenttransaction.transit_fragment_open)             .addtobackstack(null).commit(); } 

this works first time, if crash occurs app returns first fragment , second time method passed, new replacing fragment semi-invisible. clicking button on first fragment again calls method again , fine.

obviously don't want app crash shouldn't occur, feeling there's wrong how i'm writing code.

i've had same problem happen me, , because loaded fragment in oncreate of activity, without checking if there savedinstancestate, android first reopen old fragments, oncreate, added fragment on old ones without replacing them when navigate fragment, replaces top one, not bottom one, see fragments under it.

might not same thing you, might figure out.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -