Android开发中“即编即达”的用户模型

Android开发官方网站 http://developer.android.com 给咱们Android开发从入门到深刻提供了完善的文档支持。

在Dev Guide标签下,文档完整定义了Android(What is Android?),包括给出其特性、架构(底层硬件和上层软件)、自带应用、应用框架、库、运行环境以及其所带的Linux内核等信息和参数。在应用基 础(Application Fundamentals)中介绍了四大应用组件——Activities,Services,Content providers以及Broadcast receivers。等等。本项目的开发过程,一样是对这些文档进行研读的过程;不少思想和实践指导着本应用于的开发,其中使人感觉最深的是“edit in place”思想(实践)。

英文原文:(位于对Activity类进行规约的页面中。地址: http://developer.android.com/reference/android/app/Activity.html

For content provider data, we suggest that activities use a "edit in place" user model. That is, any edits a user makes are effectively made immediately without requiring an additional confirmation step. Supporting this model is generally a simple matter of following two rules:

  • When creating a new document, the backing database entry or file for it is created immediately. For example, if the user chooses to write a new e-mail, a new entry for that e-mail is created as soon as they start entering data, so that if they go to any other activity after that point this e-mail will now appear in the list of drafts.
  • When an activity's onPause() method is called, it should commit to the backing content provider or file any changes the user has made. This ensures that those changes will be seen by any other activity that is about to run. You will probably want to commit your data even more aggressively at key times during your activity's lifecycle: for example before starting a new activity, before finishing your own activity, when the user switches between input fields, etc.

This model is designed to prevent data loss when a user is navigating between activities, and allows the system to safely kill an activity (because system resources are needed somewhere else) at any time after it has been paused. Note this implies that the user pressing BACK from your activity does not mean "cancel" -- it means to leave the activity with its current contents saved away. Canceling edits in an activity must be provided through some other mechanism, such as an explicit "revert" or "undo" option.

中文译文:

对于内容提供者型数据(前文有定义),咱们建议活动体采用一种“即编即达”(或“写直达”)的用户模型。该模型是指,对用户所做出的任何编辑,没必要提供额 外的确认环节,一概使之生效(有点太绝对,有些情形下应该要先由用户确认——译者注)。要支持该模型,一般只需遵循如下两条原则便可:

  • 一个新的文档当在概念上建立的时候,在物理上(后台数据库记录或文件)就应该被当即建立了。好比,若是用户选择了写邮件,那么在用户开始 输入数据的那一刻,该邮件的一个永久存储就被建立了;这以后,若是用户跳到了其余活动体(即便退出邮件程序——译者增),该邮件都会以草稿的形式被保存。
  • 当 活动体的onPause()方法被调用时,应该将用户所做的任何更改当即写回后台数据库或文件。这确保了这些更改可以被其余即将运行的活动体获知。或许你 还可能须要更加频繁地写回这些的更改,好比在你活动体生命周期中的关键时刻:在启动一个新的活动体以前,在结束你的活动体以前,在用户切换输入域之时,等 等。
设计这一模型,是为了不用户在活动体之间穿行时致使数据丢失,并能确保系统在一个活动体被暂停以后的任什么时候刻将其杀死都是安全的(资源紧缺时系统会选择 性地杀死被暂停的活动体)。注意,这也意味着用户在运行你的应用时,按BACK键并不意味着“撤消”——而意味着保存当前活动体当前内容,然后安全离开 (这一习惯对于用习惯了Windows系统的人,会很不习惯——译者注)。活动体中的撤消编辑,必须以某种其余的机制提供,好比要给出明显的“还原”或 “撤消”选项。   
相关文章
相关标签/搜索