首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

android高效率编程之使用本地变量

2012-08-25 
android高效编程之使用本地变量hava a look at the following code you will find that ??We assign the m

android高效编程之使用本地变量

hava a look at the following code you will find that

?

?We assign the mNotesCursor field to a local variable at the start of the method. This is done as an optimization of the Android code. Accessing a local variable is much more efficient than accessing a field in the Dalvik VM, so by doing this we make only one access to the field, and five accesses to the local variable, making the routine much more efficient. It is recommended that you use this optimization when possible

?

?

?? @Override
??? protected void onListItemClick(ListView l, View v, int position, long id) {
??????? super.onListItemClick(l, v, position, id);
???????
??????? Cursor c = mNotesCursor;//We assign the mNotesCursor field to a local variable
??????? c.moveToPosition(position);
??????? Intent i = new Intent(this,NoteEdit.class);
??????? i.putExtra(NotesDbAdapter.KEY_ROWID, id);
??????? i.putExtra(NotesDbAdapter.KEY_TITLE,
??????????????? c.getString(c.getColumnIndex(NotesDbAdapter.KEY_TITLE)));
??????? i.putExtra(NotesDbAdapter.KEY_BODY,
??????????????? c.getString(c.getColumnIndex(NotesDbAdapter.KEY_BODY)));
??????? startActivityForResult(i, ACTIVITY_EDIT);
???????
??? }

热点排行