Android - onAttach(Context) not called for API 23

前端 未结 7 955
离开以前
离开以前 2020-12-08 05:46

I\'ve updated the SDK to the latest version (API 23) and the onAttach(Activity) method for fragment is deprecated. So instead of using that method, now I\'m usi

7条回答
  •  被撕碎了的回忆
    2020-12-08 06:46

    @Override
    public void onAttach(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            super.onAttach(context);
            onAttachToContext(context);
        } else {
            Activity activity = getActivity();
            super.onAttach(activity);
            onAttachToContext(activity);
        }
    }
    

提交回复
热议问题