User Interface Coding Tips

转载 2010年05月24日 14:18:00

原文地址: ... 627360&vernum=0

今天无意中发现一个关于BB UI设计的tips,拿来分享一下。
《User Interface Coding Tips 》
- Scott Wahl, Manager, Software Documentation, RIM

Three Tips for Managing Screens

   1. Pop screens off the UI stack when the user finishes interacting with them to avoid memory problems as the display stack grows.

   2. Never pop the same screen more than once. Excess popping can lead to problems with the keyboard and thumb wheel.

   3. Avoid using more than a few modal screens at one time because each screen uses a thread.

Handling Threads

An application can access the UI either on the event thread or with the event lock held. Only one thread at a time (usually the event-dispatching thread) can gain access to an interface component. There are two ways for background threads to access the UI from outside the main event-handling or UI drawing code:

   1. Acquire and hold the event lock
   2. Use invokeLater() or invokeAndWait() to run on the event dispatch thread

Holding the Event Lock

The event dispatcher sets a lock on the event thread while it processes a message. Background threads can access the UI by acquiring this lock for a short time without interfering with processing by the event dispatcher. A worker thread can call Application.getEventLock() to retrieve the event lock and then synchronize this object to ensure serialized access to the UI. You should only hold this lock for short periods of time because the event dispatcher is paused. An application should never call notify() or wait() on this object.

For example, in a timer task, you could write code in the following method:

class MyTimerTask extends TimerTask {
   public void run() {
     synchronized(Application.getEventLock()) {
         _label.setText("new text " + System.currentTimeMillis());

In most cases, this is the most efficient way to access the UI.

Running on the Event Dispatch Thread

In some cases holding the event lock is not appropriate, particularly if the application has its own locking operations to manage. In this case you must create a class that implements the Runnable interface. You can then invoke its run() method on the event dispatch thread using one of these three methods:

   1. invokeAndWait(Runnable runnable)
      Immediately calls run() on the event dispatch thread. The call blocks until the run() method is completed

   2. invokeLater(Runnable runnable)
      Calls run() on the event dispatch thread after all pending events are processed.

   3. invokeLater(Runnable runnable, long time, Boolean repeat)
      Calls run() on the event dispatch thread after a specified amount of time, where time specifies the number of milliseconds to wait before adding Runnable to the event queue. If repeat is true, Runnable is added to the event queue every time milliseconds.

Using activate()

The system calls the activate() method when it brings an application to the foreground. For most applications, you should not override activate(). Perform any initialization, including any required pushScreen() calls, in the application’s constructor. If you must override activate(), ensure that you call super.activate() from within the overridden method; otherwise, your application does not repaint correctly. Because activate() can be called multiple times for the same application, it is not appropriate to perform a one-time initialization with this method. For example, you should not perform actions, such as call pushScreen() from within activate(), unless you verify that you have done so already.

Exiting Applications

When the user closes an application (for example, by selecting the Close menu option), most applications should shut down using System.exit() before returning the user to the Home screen. This conserves space on the handheld.

 图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)

图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)是指采用图形方式显示的计算机操作用户界面。与早期计算机使用的命令行界面相比,图形界面对于用户来说在视觉上...
  • wbw1985
  • wbw1985
  • 2010年01月25日 17:14
  • 5313

Installer User Interface Mode Not Supported解决方法

今天在安装某个程序的时候,报了如下的错误: Installer User Interface Mode Not Supported,不支持安装程序的用户界面模式 感觉像是不兼容的问题,所以,...
  • zp357252539
  • zp357252539
  • 2017年02月22日 13:59
  • 3765

Coding Tips

1. for循环是开界的。它的一般形式为: for(; 条件表达式>; ) 语句; 初始化总是一个赋值语句, 它用来给循环控制变量赋初值; 条件表达式是一个关系表达式, 它决定什么时候退出...
  • anlou
  • anlou
  • 2012年09月01日 15:21
  • 297

User Interface Design Tips, Techniques, and Principles

URL: fundamental reality of appli...
  • coofucoo
  • coofucoo
  • 2006年04月15日 17:09
  • 1864

coding tips

1. Linux 动态连接库需要存取主程序里定义的全局变量,在链接主程序的时候,gcc 加上 -Wl,--export-dynamic 参数。 2. automake configer 自定...
  • HuangLiGuan
  • HuangLiGuan
  • 2018年01月04日 11:08
  • 11

UI即User Interface(用户界面)的简称

UI即User Interface(用户界面)的简称
  • cddchina
  • cddchina
  • 2013年07月31日 09:30
  • 1449


文章出处: 主要内容: 情景一:coding.net上本来就有项目(比如:你新...
  • baidu_25537855
  • baidu_25537855
  • 2016年09月06日 17:16
  • 608

Python常见问题(7):Python图形用户接口 Graphic User Interface FAQ

Contents Graphic User Interface FAQ What platform-independent GUI toolkits exist for Python?...
  • GarfieldEr007
  • GarfieldEr007
  • 2016年05月13日 17:39
  • 780

黑马程序员_java基础-图形用户接口GUI(Graphical User Interface)

图形用户接口GUI(GraphicalUser Interface) GUI用图形的方式,来显示计算机操作的界面,这样更方便更直观. CLI(Command line User Interface)命...
  • zhengylsc
  • zhengylsc
  • 2013年11月23日 16:12
  • 1457

Android官方文档之User Interface(Settings)

设置页面(Settings)用于修改、保存app的特性或行为 等。如某些新闻app可以在设置页面设置其白天/夜间模式、清除缓存、是否允许推送通知等。如下图所示。 如需为应用提供设置页面,应使用And...
  • vanpersie_9987
  • vanpersie_9987
  • 2016年07月19日 09:05
  • 1818
您举报文章:User Interface Coding Tips