当我使用postGlobalScreen推送此屏幕时,为什么屏幕上的按钮不起作用?

时间:2012-02-18 04:12:50

标签: blackberry

我编辑Blackberry_App_Descriptor.xml以使我的应用程序为“启动时自动运行”。我的应用程序有3个类,myApp,screen1和screen2。 MyApp用main方法推送screen1。在screen1中有一个按钮来推送屏幕2.当我手动启动appplication时它运行正常。 (单击应用程序图标)

问题是:

我使用RealTimeListener总是每分钟检查一次,如果它是1h30则会推送screen1,(我使用postGlobalScreen方法推送Screen1)。它推动了成功。但是我可以使用这个屏幕上的按钮1,我点击了它,而不是推到屏幕2。

我尝试使用Alternate Entry点来检查时间并推送screen1,但结果相同。

有人可以帮我解决并解释这个问题吗?

// MyApp.java
   public class MyApp extends UiApplication implements RealtimeClockListener
    {
        /**
         * Entry point for application
         * @param args Command line arguments (not used)
         */ 

        public static void main(String[] args)
        {
            // Create a new instance of the application and make the currently
            // running thread the application's event dispatch thread.
            MyApp theApp = new MyApp();  
            theApp.enterEventDispatcher();
        }


        /**
         * Creates a new MyApp object
         */
        public MyApp()
        {        
            // Push a screen onto the UI stack for rendering.
            pushScreen(new Screen1());
            addRealtimeClockListener(this);


        }


        public void clockUpdated() {
            int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
            int minute = Calendar.getInstance().get(Calendar.MINUTE);
            if(hour==1 && minute == 30){    

                UiApplication.getUiApplication().pushGlobalScreen(new Screen1(),1,UiEngine.GLOBAL_MODAL);           
            }

        }



    }


//Screen1.java
public final class Screen1 extends MainScreen implements FieldChangeListener
{
    /**
     * Creates a new MyScreen object
     */
    ButtonField button;
    public Screen1()
    {        
        button = new ButtonField("Screen 1 ");
        button.setChangeListener(this);
        add(button);


    }
    public void fieldChanged(Field field, int context) {
        if(field==button){
            UiApplication.getUiApplication().pushScreen(new Screen2());

        }

    }

}

//Screen2.java
public final class Screen2 extends MainScreen implements FieldChangeListener
{
    /**
     * Creates a new MyScreen object
     */
    ButtonField button;
    public Screen2()
    {        
        button = new ButtonField("Screen2");
        button.setChangeListener(this);
        add(button);


    }
    public void fieldChanged(Field field, int context) {
        if(field==button){
            UiApplication.getUiApplication().pushScreen(new Screen1());
        }

    }
}

1 个答案:

答案 0 :(得分:1)

请尝试以下。这里集中讨论两点

1)应用程序在后台运行

2)将后台应用程序发送到前台

package mypackage;

import java.util.Calendar;

import net.rim.device.api.system.RealtimeClockListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;

public class MyApp extends UiApplication implements RealtimeClockListener
{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public  static MyApp theApp=null;
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        theApp = new MyApp();  
        theApp.enterEventDispatcher();
    }


    /**
     * Creates a new MyApp object
     */
    public MyApp()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new Screen1());
        addRealtimeClockListener(this);
    }


    public void clockUpdated() {
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        int minute = Calendar.getInstance().get(Calendar.MINUTE);
      //  if(hour==1 && minute == 30){    
        if(!theApp.isForeground())
        {
            UiApplication.getUiApplication().pushGlobalScreen(new Screen1(),1,UiEngine.GLOBAL_MODAL);           
        }

    }
}

screen1.java

package mypackage;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

public final class Screen1 extends MainScreen implements FieldChangeListener
{
    /**
     * Creates a new MyScreen object
     */
    ButtonField button;
    public Screen1()
    {        
        button = new ButtonField("Screen 1 ");
        button.setChangeListener(this);
        add(button);


    }
    public void fieldChanged(Field field, int context) {
        if(field==button){
            close();
            MyApp.theApp.requestForeground();
            UiApplication.getUiApplication().pushScreen(new Screen2());

        }

    }
    public boolean onClose() {
        MyApp.theApp.requestBackground();
        return true;
    }

}

screen2.java

package mypackage;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

public final class Screen2 extends MainScreen implements FieldChangeListener
{
    /**
     * Creates a new MyScreen object
     */
    ButtonField button;
    public Screen2()
    {        
        button = new ButtonField("Screen2");
        button.setChangeListener(this);
        add(button);


    }
    public void fieldChanged(Field field, int context) {
        if(field==button){
            UiApplication.getUiApplication().pushScreen(new Screen1());
        }

    }
}