0

我正在使用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;
            }
        };
    }
}
4

1 回答 1

3

这完全取决于您希望您的亲密行为如何发挥作用。另外,我只能阅读英文,所以我不能 100% 确定你Dialog说什么。我假设这与关闭应用程序有关(是或否)?

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

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;
      }
   }
}  
于 2012-06-29T04:00:49.640 回答