Android 设计思想
2010-06-17 03:29:00 来源:WEB开发网这是一个组件级概念(与性能和响应性的类和方法级概念相对)。关于如何与Android系统集成的文章提供了写与系统其他部分友好协作代码的小贴士和最佳实践。
不要放弃数据
Always keep in mind that Android is a phone platform. It may seem obvious to say it, but it’s important to remember that another Activity (such as the “Incoming Phone Call” app) can pop up over your own Activity at any moment. This will fire the onFreeze() and onPause() methods, and will likely result in your application being killed.
If the user was editing data in your application when the other Activity appeared, your application will likely lose that data when your application is killed. Unless, of course, you save the work in progress first. The “Android Way” is to do just that: Android applications that accept or edit input should override the onFreeze() method and save their state in some appropriate fashion. When the user revisits the application, she should be able to retrieve her data.
A classic example of a good use of this behavior is a mail application. If the user was composing an email when another Activity started up, the application should save the in-process email as a draft.
请记住Andriod是一个电话平台。很明显可以这么说,最重要的是要记住,随时都有可能另外一个活动的程序抢占的当前活动的程序(比如:“来电” 程序)。这将会调用OnFreeze()和OnPause()方法,并将可能导致你的程序被关闭。如果用户正在你的程序中编辑数据,当另外一个行为出现,你的程序可能被关闭而丢失数据。当然,除非你在处理前就保存工作进度。“Android 的方法”是这样做的:Android程序接收或编辑输入需要重载OnFreeze(),在适当的时候并保存它们的状态。当用户再次打开应用时,能够重新恢复数据。一个经典的例子就是邮件程序。当另一个行为启动时,如果用户正在写一封邮件,程序将要保存当前的进度到草稿箱里。
没人想要数据是裸露的
(No One Wants to See Your Data Naked)
If you wouldn’t walk down the street in your underwear, neither should your
更多精彩
赞助商链接