问题描述
我是一个Android初学者。在尝试管理活动生命周期的代码时,遇到了一个新的事情。
解决方案> @SuppressLint(NewApi)是Android Lint工具使用的注释。
Lint会告诉你每当您的代码中的某些东西不是最佳的或可能崩溃。通过传递 NewApi ,您可以抑制所有警告,告诉您如果您在 minSdkVersion
查看Lint支票的完整列表,包括NewApi - 这里:
I am an android beginner. While trying a code of managing activity life cycle, I encountered a new thing.
package com.example.activitylaunch; import android.os.Build; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.ActionBar; import android.app.Activity; import android.view.Menu; import android.widget.TextView; @SuppressLint("NewApi") public class MainActivity extends Activity { TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (TextView) findViewById(R.id.text_message); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(false); } } @Override public void onDestroy(){ super.onDestroy(); android.os.Debug.stopMethodTracing(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }I understood the code well, but it gave an error in ActionBar SuppressLint. When I double clicked it, @SuppressLint("NewApi") is being added. What is meant by @SuppressLint("NewApi") here?
解决方案@SuppressLint("NewApi") is an annotation used by the Android Lint tool.
Lint will tell you whenever something in your code isn't optimal or may crash. By passing NewApi there, you're suppressing all warnings that would tell you if you're using any API introduced after your minSdkVersion
See a full list of Lint checks - including "NewApi" - here: http://tools.android.com/tips/lint-checks
这篇关于了解@SuppressLint(“NewApi”)注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!