调用要求API级别11(当前最小为9)android.app.Activity#onCreateView [英] Call requires API level 11(current min is 9) android.app.Activity#onCreateView

查看:100
本文介绍了调用要求API级别11(当前最小为9)android.app.Activity#onCreateView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SDK更新(23)之后,出现此lint错误,我的代码未做任何更改,并且在api级别为9的设备上运行正常.我也不调用android.app.Activity我的代码中根本没有#onCreateView.如果我单击自动修复,则将@SuppressLint("NewApi")放入此类的类@SuppressLint("NewApi") public class MyActivity extends android.support.v4.app.FragmentActivity的声明中,并且错误消失了,我想确定这是否是可行的方法.

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 android.app.Activity#onCreateView in my code at all. If i click the auto fix, it puts @SuppressLint("NewApi") to the declaration of the class @SuppressLint("NewApi") public class MyActivity extends android.support.v4.app.FragmentActivitylike this and error goes away, I want to be sure if this is the way to go.

推荐答案

我也遇到了相同的问题.

I encountered the same issue as well.

如果您查看Activity类的javadoc(

If you take a look at the javadoc for the Activity class (http://developer.android.com/reference/android/app/Activity.html#onCreateView%28android.view.View,%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.

我没有在类声明级别使用@SuppressLint("NewApi"),而是在代码中添加了该特定方法,并取消了方法声明的lint警告.像这样:

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:

@SuppressLint("NewApi")
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;
}

这样,将来仍可以通过lint检查该类代码中的任何附加内容,但是lint将停止用错误标记该方法.

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表示,两个onCreateView(...)方法均将null作为默认行为返回,并且pre API 11方法具有空的实现.

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.

这篇关于调用要求API级别11(当前最小为9)android.app.Activity#onCreateView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆