黑莓无法关闭屏幕

时间:2012-06-29 02:48:10

标签: blackberry screen

我正在使用finish()在Android中退出应用程序之前关闭当前活动。

但是,我无法关闭黑莓屏幕。

public class Main_AllLatestNews extends MainScreen {

public Main_AllLatestNews() {
    super(USE_ALL_WIDTH);
}

private boolean Dialog() {
    final Bitmap logo = Bitmap.getBitmapResource("icon.png");
    d = new Dialog("确定离开?", new String[] { "是", "否" }, new int[] {
            Dialog.OK, Dialog.CANCEL }, Dialog.OK,
            logo) {
        public void setChangeListener(FieldChangeListener listener) {
            if (d.getSelectedValue() == Dialog.OK) {

            } else {
                d.close();
            }
        };
    };
    d.show();
    return (d.doModal() == Dialog.OK);
}

public boolean onClose(){
    if(Dialog()){
        System.exit(0);
        return true;
    }else
        return false;
}
}

这是我的Main班级

public class Main extends UiApplication {
public static void main(String[] args) {
    Main theApp = new Main();
    theApp.enterEventDispatcher();
}

public Main() {
    pushScreen(new MyScreen());
}

public final class MyScreen extends MainScreen {
    private Bitmap logo = Bitmap.getBitmapResource("logo_page.png");
    private BitmapField bmfield;

    public MyScreen() {
        setTitle("Oriental Daily");

        bmfield = new BitmapField(logo, Field.FIELD_HCENTER
                | BitmapField.FOCUSABLE) {
            protected boolean navigationClick(int status, int time) {
                Main.this.pushScreen(new Main_AllLatestNews());
                Main.this.popScreen(MyScreen.this);
                return true;
            }
        };
    }
}

1 个答案:

答案 0 :(得分:3)

这取决于您希望关闭行为的确切方式。另外,我只能阅读英文,所以我不能100%确定Dialog所说的内容。我假设它与关闭应用程序有关(是或否)?

无论如何,通常,我的应用程序通过覆盖onClose()子类中的MainScreen方法来关闭。您实际上不需要侦听转义键。当用户完全退出应用程序时,onClose()将被正常调用,或者按下带有黑莓图标的小按钮,然后选择关闭

public final class MyScreen extends MainScreen {

   /** @return true if the user chooses to close the app */
   private boolean showDialog() {       
      Bitmap logo = Bitmap.getBitmapResource("icon.png");
      Dialog d = new Dialog("确定离开?", 
            new String[] { "是", "否" }, 
            new int[] { Dialog.OK, Dialog.CANCEL }, 
            Dialog.OK,
            logo);       
      return (d.doModal() == Dialog.OK);
   }       


   /** Shutdown the app? */
   public boolean onClose() {
      if (showDialog()) {       
         System.exit(0);
         return true;
      } else {
         // the user does not want to exit yet
         return false;
      }
   }
}