tags:

views:

37

answers:

1

Hi all,

I have a Listener class which implements ViewListener (contains two methods, open, close, which will fire when any monitored mailbox's email is open/closed). So this is called from a class App extending UiApplication, and when i read a email, the open method is fired, i would like to call my original (App class) with a specific Screen (sending a message to app would be good enough). Currently i have it so that App have a static variable that stores the instance of app that's running on the device. I used that to call a method to change screen, but it doesn't actually bring it up. app.requestForeground() doesn't seem to work either.

Any ideas?

Thanks a lot!

A: 

Have you tried using ApplicationManager to handle this? If you have a background system process listening for events, it may be possible that your GUI process isn't even running (i.e. if you did a System.exit(0) rather than backgrounding it). Here's a snippet of code you can use to look for the GUI process (based on its app descriptor) and either bring it to the foreground (if it's running) or launch it (if it's not):

// Check if app is already running
ApplicationDescriptor descriptor = [descriptor for your GUI entrypoint];
ApplicationManager appManager = ApplicationManager.getApplicationManager();
int pid = appManager.getProcessId(descriptor);
if (pid != -1) {
    // App is running, bring it to the foreground
    appManager.requestForeground(pid);
} else {
    // App is not running, so launch it
    try {
        appManager.runApplication(descriptor);
    } catch (ApplicationManagerException e) {
        // Can't launch
    }
}

To get the app descriptor for your GUI entry point, use the following methodology:

  1. Get the module handle using CodeModuleManager.getModuleHandleForClass(MyApp.class)
  2. Get a list of app descriptors for the handle using CodeModuleManager.getApplicationDescriptors(handle)
  3. Check the flags on each descriptor until you find one equal to "0". This means it is not a system/auto-start/run-on-startup descriptor - probably your GUI entry point.
Marc Novakowski
A question, what/where is the descriptor for the gui entrypoint?
FurtiveFelon
I edited the answer to include that information
Marc Novakowski