Exersise 1:

把多个字段关联到一个row里面

In the future, remember that the mapping between the from columns and to resources is done using the respective ordering of the two arrays. If we had more columns we wanted to bind, and more Views to bind them in to, we would specify them in order, for example we might use { NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_BODY } and { R.id.text1, R.id.text2 } to bind two fields(字段) into the row (and we would also need to define text2 in the notes_row.xml, for the body text). This is how you can bind multiple fields into a single row (and get a custom row layout as well).

为什么好多函数都需要一个Context参数:

The constructor for NotesDbAdapter takes a Context, which allows it to communicate with aspects of the Android operating system. This is quite common for classes that need to touch the Android system in some way. The Activity class implements the Context class, so usually you will just pass this from your Activity, when needing a Context.

Like many classes in Android, the SimpleCursorAdapter needs a Context in order to do its work, so we pass in this for the context (since subclasses of Activity implement Context).

Exercise 2:

有时候得声明 local variable 来方便我们使用 Dalvik VM里面的variable

Note: 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.

startActivityForResult() 和onActivityResult() 经常用于跨进程调用

onActivityResult() is the overridden method which will be called when an Activity returns with a result. (Remember, an Activity will only return a result if launched with startActivityForResult.)

The combination of startActivityForResult() and onActivityResult() can be thought of as an asynchronous RPC (remote procedure call) and forms the recommended way for an Activity to invoke another and share services.

Exercise 3:

onSaveInstanceState() , onPause(), onResume()方法

onSaveInstanceState() is called by Android if the Activity is being stopped and may be killed before it is resumed! This means it should store any state necessary to re-initialize to the same condition when the Activity is restarted. It is the counterpart to the onCreate() method, and in fact the savedInstanceState Bundle passed in to onCreate() is the same Bundle that you construct as outState in the onSaveInstanceState() method.

onPause() and onResume() are also complimentary methods. onPause() is always called when the Activity ends, even if we instigated that (with a finish() call for example). We will use this to save the current note back to the database. Good practice is to release any resources that can be released during an onPause() as well, to take up less resources when in the passive state. onResume() will call our populateFields() method to read the note out of the database again and populate the fields.

更多相关文章

  1. Android Activity的onCreate()函数
  2. Android RectF类的构造函数参数说明
  3. android 读取SD卡或者其他地方文件功能函数
  4. Android Audio代码分析19 - setPosition函数
  5. Android Audio代码分析23 - attachAuxEffect函数

随机推荐

  1. 可编辑表格,固定抬头
  2. 点击弹出球
  3. 固定导航栏
  4. github的clone有安装不了依赖的问题错误
  5. JS操作DOM,两个简单的小案例
  6. js实现简单好玩的气泡
  7. 鞋子怎么画?各种角度鞋子的绘画教程!
  8. 拖动的页面 滚动导航固定上方
  9. 一个可编辑的表格 双击进行编辑,回车确认
  10. Qwery - 多用途企业商务网站模板WordPres