title: previous instance still active error in blackberry
body: <p>I created app which user can start from menu and from icon. I do not use GlobalEventListener in my app, just register ApplicationMenuitem. And now I am getting error: previous instance still active when launch my app. </p>
  
  <p>Steps to reproduce not so trivial: </p>
  
  <ol>
  <li><p>launch app from icon</p></li>
  <li><p>do not close it, just switch to another app</p></li>
  <li><p>launch app from icon again</p></li>
  </ol>
  
  <p>I founded <a href="http://supportforums.blackberry.com/t5/Java-Development/Help-with-quot-previous-instance-still-active-quot-message/td-p/402839" rel="nofollow">article</a> in blackberry's forum about it , but I can't find solution where I should remove my ApplicationMenuItem: it added on phone boot and should show all the time.</p>
  
  <p>My code:</p>
  
  <pre><code>public class Jingu extends UiApplication {
  
  public static void main(String[] args) {
      ApplicationManager app = ApplicationManager.getApplicationManager();
      boolean keepGoing = true;
      while (keepGoing) {
          if (app.inStartup()) {
              try {
                  Thread.sleep(1000);
              } catch (Exception e) {}
          } else {
              keepGoing = false;
          }
      }
  
      Jingu theApp = new Jingu();
      theApp.initMenuItem();
      theApp.showMainScreen();
      theApp.enterEventDispatcher();
  }
  
  public Jingu() {
  
  }
  
  public void showMainScreen() {
      showScreen(new JinguMainScreen(this));
  }
  
  public void initMenuItem() {
      // Create menu item
      Object o = RuntimeStore.getRuntimeStore().get(JinguMenuItem.MY_MENU_ID);
      // register only if not done already.
      if (o == null) {
          new JinguMenuItem(this).registerInstance();
      }
  }
  
  
  
  public void showScreen(Screen aScreen) {
      synchronized (Application.getEventLock()) {
  
          try {
              UiApplication.getUiApplication().popScreen(aScreen);
          } catch (Exception e) {
          }
  
          UiApplication.getUiApplication().pushScreen(aScreen);
      }
  }
  
  }
  
  public class JinguMenuItem extends ApplicationMenuItem {
  public static final long MY_MENU_ID = 0xb9739d5240d5943dL;
  private final Jingu jingu;
  
  public JinguMenuItem(Jingu jingu) {
      super(0x350100);
      this.jingu = jingu;
  }
  
  public void registerInstance() {
      Object menuItem = RuntimeStore.getRuntimeStore().remove(MY_MENU_ID);
      if (menuItem == null) {
          ApplicationMenuItemRepository amir =                            ApplicationMenuItemRepository.getInstance();
          amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM, this);
          RuntimeStore.getRuntimeStore().put(MY_MENU_ID, this);
      }
  }
  
  
  public Object run(Object context) {
      jingu.setDefaultFont(Font.getDefault());
      jingu.setMainApp(false);
      jingu.setBbmEditField(null);
  
      jingu.showMainScreen();
  
      return context;
  }
  
  public String toString() {
      return "My Menu";
  }
  }
  </code></pre>
  
  <p>plz advice where I should delete ApplicationMenuItem in my app?</p>
  
  <p>my regards,</p>
  
  <p>Vadim</p>