Android 设计思想
2010-06-17 03:29:00 来源:WEB开发网Instead of spawning Activities directly from the background, you should instead use the NotificationManager to set Notifications. These will appear in the status bar, and the user can then click on them at his leisure, to see what your application has to show him.
(Note that all this doesn’t apply to cases where your own Activity is already in the foreground: in that case, the user expects to see your next Activity in response to input.)
不要打断正在通话中的用户
如果用户正在运行一个程序(如:通话期间的电话程序),并需要高可靠性。这是为什么忽略新的活动除了用户在当前程序的输入的直接反馈。也就是说,不要让在后台的服务程序或接收程序产生行为。这样做会打断当前运行的程序,并会导致骚扰用户。可能更糟糕是,你的行为可能变成“键盘监视”去接收一些用户的输入。如果你的程序做了这些,这将是一个坏消息。
替换在后台直接产生活动,你需要用NotificationManager来设置通知。这些通知将出现在状态栏,等用户有空的时候可以点击他们,来查看你的程序要做的事前。
(注意:以上所说的不适合于你的活动已经运行在后台,在这样情况下,用户是想看看到输入的下个的活动的)
做大量的事,放到线程中去
If your application needs to perform some expensive or long-running computation, you should probably move it to a thread. This will prevent the dreaded “Application Not Responding” dialog from being displayed to the user, with the ultimate result being the fiery demise of your application.
By default, all code in an Activity as well as all its Views runs in the same thread. This is the same thread that also handles UI events. For example, when the user presses a key, a key-down event is added to the Activity’s main thread’s queue. The event handler system needs to dequeue and handle that event quickly; if it doesn’t, the system concludes after a few seconds that the application is hung and offers to kill it for the user.
If you have long-running code, running it inline in your Activity will run
更多精彩
赞助商链接