android - App Crashes when clicking in different TextViews very fast -


i new android , have fragment container view (a framelayout). there 2 textviews on top of it, tabs. each textview ie txt1,txt2 adds 2 fragments ie frgmnt1,frgmnt2 respectively. when textview clicked, corresponding fragment added. if clicked again, fragment removed.

that part working fine. however, when click in textview rapidly, app crashes , shows "no host" exception. can me understand why happens?

(side note, tab layout implementation not required here).

here stack trace:

07-04 18:22:25.600 10971-10971/integral.com.sellfie e/androidruntime: fatal exception: main process: integral.com.sellfie, pid: 10971 java.lang.illegalstateexception: no host     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1239)     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1234)     @ android.support.v4.app.fragmentmanagerimpl.dispatchactivitycreated(fragmentmanager.java:2046)     @ android.support.v4.app.fragment.performactivitycreated(fragment.java:1989)     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1092)     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1252)     @ android.support.v4.app.backstackrecord.run(backstackrecord.java:742)     @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1617)     @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:570)     @ integral.com.sellfie.fragments.memberfragment.addfragment(memberfragment.java:319)     @ integral.com.sellfie.fragments.memberfragment.showfragment(memberfragment.java:270)     @ integral.com.sellfie.fragments.memberfragment$3.onclick(memberfragment.java:242)     @ android.view.view.performclick(view.java:5207)     @ android.view.view$performclick.run(view.java:21168)     @ android.os.handler.handlecallback(handler.java:746)     @ android.os.handler.dispatchmessage(handler.java:95)     @ android.os.looper.loop(looper.java:148)     @ android.app.activitythread.main(activitythread.java:5443)     @ java.lang.reflect.method.invoke(native method)     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:728)     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618) 

hoping you.you need change fragments using method below.

note : here i'm not using support fragments change code accordingly.

 //change fragment in appropriate container      private void changefragment(fragment fragment) {             if (fragment !=          getfragmentmanager().findfragmentbyid(r.id.frame_container)) {          fragmenttransaction transaction = getfragmentmanager().begintransaction();                     //now implementing hack                     if (oldfragment != null)                         transaction.detach(oldfrag);                     transaction.replace(r.id.frame_container, fragment);                     transaction.attach(fragment);                     transaction.commit();                     oldfragment = fragment;                 }             } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -