Skip to content Skip to sidebar Skip to footer

Not Able To Update Fragment Ui From Onactivityresult

I'm working on an app in which has a class that extends FragmentActivity. In the onResume() method I was calling a class for which I am sending the reference of this fragmentactivi

Solution 1:

...but when I click on the button I'm Calling startActivityForResult() which in turn receives results in OnActivityResult() in which I'm trying to update the text of EditText , but it is not happening. When I clicked back button I'm able to see the text on EditText changed

I think this is happening because of the use of LoadScreenHelper in the onResume method of the FragmentActivity. Keep in mind that onResume will always be called when the activity comes to the foregound, this will also happen after the Activity started with startActivityForResult will return. Now by calling LoadScreenHelper's loadTargetScreen() method, you'll always add a new MultiFormScreenFragment to the initial FragmentActivity. When you come back from the child Activity the onResume method will be called again and a new MultiFormScreenFragment will be created most likely covering the initially added fragment. If you click the back button this top fragment will be removed from the screen leaving the initially added fragment.

As I don't know what you're trying to do in the end with the LoadScreenHelper class I would suggest to either move the line:

newLoadScreenHelper((FragmentActivity)context, R.id.fragment_container).loadTargetScreen("", 1,"",1,false,"","","");

in the onCreate method so it's executed only once, or insert a check in the loadTargetScreen method to find out if an instance of the MultiFormScreenFragment isn't already in the layout(use the FragmentManager to find the fragment). If it is already in the layout then do nothing else add a new instance of the fragment.

Post a Comment for "Not Able To Update Fragment Ui From Onactivityresult"