Skip to content

Instantly share code, notes, and snippets.

@Kishanjvaghela
Created April 29, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kishanjvaghela/7339260c2c4c0552cdaef237fc25365b to your computer and use it in GitHub Desktop.
Save Kishanjvaghela/7339260c2c4c0552cdaef237fc25365b to your computer and use it in GitHub Desktop.
/*
* onAttach(Context) is not called on pre API 23 versions of Android and onAttach(Activity) is deprecated
* Use onAttachToContext instead
*/
@TargetApi(23)
@Override
public void onAttach(Context context) {
super.onAttach(context);
onAttachToContext(context);
}
/*
* Deprecated on API 23
* Use onAttachToContext instead
*/
@SuppressWarnings("deprecation")
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
onAttachToContext(activity);
}
}
/*
* Called when the fragment attaches to the context
*/
protected void onAttachToContext(Context context) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment