SuppressLint 总结

1、@SuppressLint("DrawAllocation")

>警告提示

Avoid object allocations during draw/layout operations (preallocate and reuse instead) less... (Ctrl+F1) 
You should avoid allocating objects during a drawing or layout operation. These are called frequently, so a smooth UI can be interrupted by garbage collection pauses caused by the object allocations.  The way this is generally handled is to allocate the needed objects up front and to reuse them for each drawing operation.  Some methods allocate memory on your behalf (such as Bitmap.create), and these should be handled in the same way.

> 提示 已经很清楚 就是 避免在实例化操作(提前分配并在draw和layout的时候 直接使用)

实例化操作会阻碍 垃圾回收机制 ,使 界面卡顿。

>解决

将 Paint 、RectF 等声明并初始化未全局变量,可以在onDraw或onLayout时 进行赋值操作。

 

2、@SuppressLint("CommitPrefEdits")

     SharedPreferences.edit() without a corresponding commit() or apply() call less... (Ctrl+F1) 
After calling edit() on a SharedPreference, you must call commit() or apply() on the editor to save the results.

sharedPreferences.edit()时 获取到的Editor必须 使用 commit 或 apply 来完成操作。所以再 没有写 commit或 apply之前 或提示@SuppressLint("CommitPrefEdits")
      ——Editor的 commit 和 apply 相比,apply效率 跟高, commit 方法 返回 boolean类型,判断是否存储成功 。简略解释:apply先将数据存储到内存,再异步操作存储到磁盘,而 commit:写数据时就同步写到磁盘中了,所以效率会低一些。

 

3、@SuppressLint("RestrictedApi") 

 

 ,个人理解 代码中也就是这个意思,既然不想被使用,那应该还存在其他的替代方式,就尽量不要使用。

 

 

 

 

--未完 待续,持续更新

/* * 这个类主要包括五个点击事件,分别为 * 1,ListView的长按点击事件,用来AlertDialog来判断是否删除数据。 * 2,ListView的点击事件,跳转到第二个界面,用来修改数据 * 4,menu里的退出事件,用来退出程序 * 5,menu里的新建事件,用来新建便签 * 6,对返回按钮监听退出程序 */ public class MainActivity extends Activity { // 定义帮助类 private MyOpenHelper notesDB; // 定义数据库类 private SQLiteDatabase dbReader;// 读取 // 定义组件 private ListView lv; private Button bt; private TextView tvBody; private TextView tvTitle; // 数据库表名称 private static final String TABLE_NAME = "data"; // 定义选项菜单 private static final int DB_ISNERT = 0x11; private static final int EXIT = 0x12; // 定义上下文菜单 private static final int DB_DELETE = 0x22; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt = (Button) findViewById(R.id.button1); // 实例化数据库对象 notesDB = new MyOpenHelper(this); // 创建数据库 dbReader = notesDB.getWritableDatabase(); // 取出组件 lv = (ListView) findViewById(R.id.listView1); // 设置监听 // 注册ListView上下文菜单 this.registerForContextMenu(lv); // 一打开软件就进行数据库查询把数据库中的内容查询显示 queryData(); // 短按时跳到第二个界面进行查看,修改 lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub Cursor c = dbReader.query(TABLE_NAME, null, null, null, null, null, null); c.moveToPosition(position);// 移动光标到一个绝对的位置 Intent i = new Intent(MainActivity.this, SecondAtivity.class); String s = String.valueOf(id); i.putExtra(SecondAtivity.mRowId, s); i.putExtra(SecondAtivity.KEY_BODY, c.getString(c.getColumnIndex(SecondAtivity.KEY_BODY))); i.putExtra(SecondAtivity.KEY_TITLE, c.getString(c.getColumnIndex(SecondAtivity.KEY_TITLE))); // 把数据库中的内容传到SecondAtivity startActivityForResult(i, 1); } }); } /** * 填充ListView */ public void queryData() { // 游标 查询数据库 Cursor cursor = dbReader.query(TABLE_NAME, null, null, null, nul
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值