user65721 user65721 - 9 months ago 77
Android Question

Call requires API level 11(current min is 9)

After the SDK update (23), I am getting this lint error, I haven't made any change in my code and it was working fine on devices with api level 9. Also I do not call in my code at all. If i click the auto fix, it puts @SuppressLint("NewApi") to the declaration of the class

public class MyActivity extends
like this and error goes away, I want to be sure if this is the way to go.


I encountered the same issue as well.

If you take a look at the javadoc for the Activity class (,%20java.lang.String,%20android.content.Context,%20android.util.AttributeSet%29), you'll see that the method public View onCreateView (View parent, String name, Context context, AttributeSet attrs) was added in API 11.

Rather than using @SuppressLint("NewApi") at the class declaration level, I added that particular method to my code and suppressed the lint warning for the method declaration. Like so:

public View onCreateView(View parent, String name, Context context, AttributeSet attrs)
    if(Build.VERSION.SDK_INT >= 11)
      return super.onCreateView(parent, name, context, attrs);
    return null;

This way any future additions to the code of the class will still get checked by lint, but lint will stop flagging this method with an error.

ETA: Javadoc for class indicates that both onCreateView(...) methods return null as the default behavior, and that the pre API 11 method has an empty implementation.