java.lang.IllegalStateException: Fragment not attached to Activity

前端 未结 12 1176
名媛妹妹
名媛妹妹 2020-11-28 02:28

I am rarely getting this error while making an API call.

java.lang.IllegalStateException: Fragment  not attached to Activity

I tried puttin

12条回答
  •  庸人自扰
    2020-11-28 02:41

    Fragment lifecycle is very complex and full of bugs, try to add:

    Activity activity = getActivity(); 
    if (isAdded() && activity != null) {
    ...
    }
    

提交回复
热议问题