Android – onAttach(Context) not called for API 23

I solved the problem in this way:

@TargetApi(23)
@Override public void onAttach(Context context) {
    //This method avoid to call super.onAttach(context) if I'm not using api 23 or more
    //if (Build.VERSION.SDK_INT >= 23) {
        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 < 23) {
        onAttachToContext(activity);
    }
}

/*
 * This method will be called from one of the two previous method
 */
protected void onAttachToContext(Context context) {}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)