Answer the question
In order to leave comments, you need to log in
ChildFramgentManager not working inside onActivityResylt in fragment. How to fix?
There is an activity (AcMain), inside this activity there are several fragments, in one of these fragments (FrOne) you need to launch a nested fragment (FrOne__FrNested) after calling onActivityResylt.
Inside FrOne is the following code:
private void clickButton() {
startActivityForResult(intent, REQUEST_CODE_ADD_VIDEO);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_ADD_VIDEO:
getChildFragmentManager().beginTransaction()
.add(layoutForAllFragmentsFR_ONE.getId(), new FrOne_FrNested))
.addToBackStack(null)
.commit();
break;
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.max.sloustep, PID: 1153
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65538, result=-1, data=Intent { dat=content://media/external/video/media/42964 flg=0x1 }} to activity {com.example.max.sloustep/com.example.max.sloustep.activities.AcMain}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.ActivityThread.deliverResults(ActivityThread.java:3852)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3895)
at android.app.ActivityThread.access$1600(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5582)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1842)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1860)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:650)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:609)
at com.example.max.sloustep.fragments.FrProfile.onActivityResult(FrProfile.java:311)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
at android.app.Activity.dispatchActivityResult(Activity.java:6526)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3848)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3895)
at android.app.ActivityThread.access$1600(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5582)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Answer the question
In order to leave comments, you need to log in
congratulations, you got into the reason why fragments are very much not used, i.e. in a very problematic life cycle. There is no universal solution, i.e. in general, yes. just stop using it.
Google recently published a pack of libs, to simplify the solution of these problems here
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question