I have a fragment which works fine basically. In the onResume method I perform an api call to get fresh data when ever a the user gets to the activity/fragment.
public void onResume(){
super.onResume();
//in pseudo
do async call
success callback
update ui
failure callback
update ui
}
This works fine most of the time. However I experience a problem when the user navigates back to the parent activity, before the update ui method has finished. The update ui just sets some text views.
E.g. when the user navigates to the activity and the fragment the above onResume is called. Immediately the users goes back to the parent activity. The async call and update ui isn't finished yet and I get:
FATAL EXCEPTION: main Process: com.project.foobar, PID: 4405 java.lang.IllegalStateException: Fragment MyDetailFragment{41ebb478} not attached to Activity
This is thrown in the update ui method after success callback. I use square's retrofit to manage api calls. And again, this just happens when update ui has not finished. When I wait for it to finish and go back everything is fine.
Any ideas what might be wrong?