android - Fragment Already active : Illegal State Exception -
i have gridview items on click of item move activity has fragment. when go activity come gridview , go activity other item fails following exception:
at android.app.activitythread.performlaunchactivity(activitythread.java:2318) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2396) @ android.app.activitythread.access$800(activitythread.java:139) @ android.app.activitythread$h.handlemessage(activitythread.java:1293) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:149) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invokenative(method.java) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:817) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:633) @ dalvik.system.nativestart.main(nativestart.java) caused by: java.lang.illegalstateexception: fragment active @ android.support.v4.app.fragment.setarguments(fragment.java:530) @ com.buzzreel.myactivity.oncreate(myactivity.java:81) @ android.app.activity.performcreate(activity.java:5411) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2270) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2396) @ android.app.activitythread.access$800(activitythread.java:139) @ android.app.activitythread$h.handlemessage(activitythread.java:1293) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:149) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invokenative(method.java) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:817) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:633) @ dalvik.system.nativestart.main(nativestart.java)
this code of fragment in myactivity oncreate():
fragment myfragment = myfragment.getinstance(); bundle profileargs = new bundle(); profileargs.putserializable("data", customobject); myfragment.setarguments(profileargs); fragmentmanager manager = getsupportfragmentmanager(); fragmenttransaction transaction = manager.begintransaction(); transaction.add(r.id.fragment_info, myfragment, "myfragment"); transaction.commit();
this getinstance method in fragment class:
public static myframgent getinstance() { return new myframgent(); }
the problem using same fragment backstack name every time click gridview item here:
transaction.add(r.id.fragment_info, myfragment, "myfragment");
what need set string null:
transaction.add(r.id.fragment_info, myfragment, null);
or if using name backstack use different name each of onclick of gridviews
Comments
Post a Comment