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

发布于 2025-01-06 23:14:38 字数 2599 浏览 2 评论 0原文

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

问题是:

我使用 RealTimeListener 总是每分钟检查一次时间,如果是 1h30 它将推送 screen1,(我使用方法 postGlobalScreen 来推送 Screen1)。它推动了成功。但我可以使用此 screen1 上的按钮,我单击了它,但它没有推送到 screen2。

我尝试使用备用入口点来检查时间并推送 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());
        }

    }
}

I edit Blackberry_App_Descriptor.xml to make my app is "Auto run on start up". My app have 3 classes, myApp, screen1 and screen2. MyApp with main method to push screen1. in screen1 have a button to push screen 2. It run OK when I launch appplication manualy. (click icon of App )

Problem is:

I use RealTimeListener to always check time each minutes, if it is 1h30 it will push screen1, ( I used method postGlobalScreen to push Screen1 ). And it pushed success. But i can use the button on this screen1, I clicked it and it not push to screen2.

I try to use Alternate Entry point to check time and push screen1 but it have the same result.

Can anybody help me solve and explain clearly about this problem ?

// 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());
        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2025-01-13 23:14:38

请尝试以下。这里集中注意两点

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());
        }

    }
}

Please try following. here concentrate on two points

1)Application run in background background

2)send background application into foreground

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());
        }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文