2012-02-18 79 views
0

我编辑Blackberry_App_Descriptor.xml,使我的应用程序是“启动时自动运行”。我的应用程序有3个类,myApp,screen1和screen2。 MyApp用主要方法推动screen1。在屏幕1中有一个按钮来推动屏幕2.当我启动应用程序manualy时,它运行正常。 (点击应用程序图标的)为什么当我使用postGlobalScreen推动这个屏幕时,屏幕上的按钮不起作用?

问题是:

我用RealTimeListener随时查询每个时间分钟,如果是1小时30分钟,将推动屏蔽1,(我用的方法postGlobalScreen推屏蔽1)。它推动了成功。但我可以使用这个屏幕上的按钮1,我点击它,它不会推到屏幕2。

我尝试使用Alternate Entry point检查时间并推送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

请试试看。这里集中在两点

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

    } 
} 
+0

太好了!感谢HelpMeToHelpYou,你是黑莓的主人:) – 2012-02-18 05:09:06

+1

不,我是黑莓的学习者 – 2012-02-18 06:45:19

相关问题