0

I have a UI application that is set to autorun on startup which spawns a few threads doing some work in the background. It has one screen that displays information about the work the background threads are doing.

class AppName extends UiApplication implements SystemListener2 {
    private static AppName app;

    public static void main(String[] args) {
        app = new AppName();

        if (ApplicationManager.getApplicationManager().inStartup()) {
            app.addSystemListener(app);
        } else {
            app.initializeLater();
        }
        app.enterEventDispatcher();
    }

    public AppName() {
        pushScreen(new InfoScreen());
        requestBackground();
    }

    private void initialize() {
        // Spawns some threads doing work in the background
    }

    private void initializeLater() {
        invokeLater(new Runnable() {
            public void run() {
                initialize();
            }
        });
    }

    public void powerUp() {
        removeSystemListener(this);
        initialize();
    }
}

When I run the app in the simulator it works fine. Upon startup everything runs and then when I click the icon the screen is foregrounded and displayed. This is the output from the simulator:

3:20:26.612: AM: Starting AppName
3:20:26.612: AM: AppName already running
3:20:26.612: AM: Foreground is requested: AppName(304)
3:20:26.628: AM: Foreground is set: AppName(304)

However, on the device the screen never displays. This is the device debugger output:

[0.0] Starting AppName
[0.0] AppName already running

As you can see the foreground request is never made. I confirmed this by overriding the UiApplication.activate() method and putting in a System.out message to see if it was being called but it's not getting called.

Does anyone have any idea why this is happening?

ruiseal
  • 301
  • 2
  • 5

1 Answers1

0

try using this

UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    public void run() {
        UiApplication.getUiApplication().requestForeground();
    });
}
edorian
  • 38,542
  • 15
  • 125
  • 143
sagar
  • 153
  • 1
  • 8