View Single Post
Old 09-13-2008, 09:48 PM   #1 (permalink)
jrebeiro
New Member
 
Join Date: Nov 2006
Location: New York, NY
Model: 8300
Carrier: AT&T, T-Mobile
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Display Dialog on startup

Please Login to Remove!

I am having trouble with the following code. I am creating a background process and would like to display a Dialog on startup. Nothing ever gets displayed. I stepped through the code and made sure that Dialog.ask gets executed but still nothing shows.

In the emulator the Media Card Insterted dialog seems to takeover the screen and my dialog gets ignored.

Here is the code:

Code:
public class GVIntercepter extends UiApplication implements SystemListener
{
    public static void main(String[] args)
    {
        // register an options provider
        GVIntercepterOptionsProvider provider = new GVIntercepterOptionsProvider();
        OptionsManager.registerOptionsProvider(provider);
        
        // register a phone handler
        PhoneHandler phone_handler = new PhoneHandler();
        Phone.addPhoneListener(phone_handler);
        
        GVIntercepter instance = new GVIntercepter();
        // instance.enterEventDispatcher();
        
        if( ApplicationManager.getApplicationManager().inStartup() ) {
          // Add a system listener to detect when system is ready and available.
          instance.addSystemListener(instance);
        } else {
          // System is already ready and available so perform your start up work now.
          // Note that this work must be completed using invokeLater because the
          // application has not yet entered the event dispatcher.
          instance.doStartupWorkLater();
        }
        // Enter the event dispatcher.
        instance.enterEventDispatcher();
    }
    
    //Invoked when the user is putting the device into a power off state.
    public void powerOff()
    { }

    //Invoked when the device has left the power off state.
    public void powerUp()
    {
      Application.getApplication().removeSystemListener(this);
      doStartupWork();
    }

    //Invoked when the internal battery voltage falls below a critical level.
    public void batteryLow()
    { }

    //Invoked when the internal battery voltage has returned to normal.
    public void batteryGood()
    { }

    //Invoked when the internal battery state has changed.
    public void batteryStatusChange(int status)
    { }
    
    private void doStartupWork()
    {
      // Perform your start up activities here!
      Application.getApplication().invokeLater( new Runnable() {
        public void run() {
          Dialog.ask(Dialog.D_YES_NO, "Display?");
        }
      } );
    }
    
    private void doStartupWorkLater()
    {
      Application.getApplication().invokeLater( new Runnable() {
        public void run() {
          doStartupWork();
        }
      } );
    }
        
    public GVIntercepter()
    {    }
}
I'm using JDE 4.2.1.

Any ideas?
Offline   Reply With Quote