Issue
Since onAttach(Activity) has been deprecated on SDK 23, which is the best method in the Fragment lifecycle for checking if an Activity is implementing an interface?
this code is no longer right and in the future this method could even be removed.
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof OnInterfaceOfFragmentListener)
mCallback = (OnInterfaceOfFragmentListener) activity;
else
throw new RuntimeException("OnInterfaceOfFragmentListener not implemented in activity");
}
Solution
The code will remain the same, just you should be using a Context parameter rather than an Activity, as per the documentation.
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnInterfaceOfFragmentListener)
mCallback = (OnInterfaceOfFragmentListener) context;
else
throw new RuntimeException("OnInterfaceOfFragmentListener not implemented in context");
}
Answered By - fractalwrench
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.