Close Blackberry Map after use of custom menu item

212 views Asked by At

I created for BlackberryMaps a own menu item with help of "MenuItem" and invoke Blackberry Maps. After using this Item the current location (MapView) should be send back to my Application. This works fine.

The problem is I found no solution for closing the app after using the menu Item. Is there a possibility to close Blackberry Maps? Or set my own App to foreground?

private static class MapMenuItem  extends ApplicationMenuItem {
//creates a new MenuItem for Blackberry Maps and defines the action which should //happen after a click on the MenuItem
            CustomDialog_GPS customDialogGps;
            StartScreen startScreen;

            MapMenuItem(StartScreen startScreen, CustomDialog_GPS customDialogGps) {
               super(20);
               this.startScreen = startScreen;  
               this.customDialogGps = customDialogGps;
            }
            public String toString() {
            //creates the name for the navigation Menu  
               String itemName = ""+_res.getString(CUSTOMDIALOG_GPS_USE_AS_NEW_LOCATION);
               return itemName;
            }
            public Object run(Object context) {
            //defines what should happen after a click on the menu

            //get the location at which the cursor is pointing at.  
               MapView mv = (MapView)context;

               if (mv != null) {                
                  //opens a method inside of CustomDialogGPS which handles the latitude and longitude                     
                   customDialogGps.saveAdjustedPosition(mv);

                  //TODO pop Screen
                  //Screen screen = (Screen)UiApplication.getUiApplication().getActiveScreen();           
               }
               else {
                    throw new IllegalStateException("Context is null, expected a MapView instance");
               }
               return null;
            }

       }
2

There are 2 answers

1
Eugen Martynov On

Unfortunately you can't close another app programmatically (Actually you can if you know where is menu item to close for example) but you can foreground your app UiApplication.getApplication().requestForeground(). What is probably appropriate solution for you.

1
Tamar On

Instead of passing the user to the Maps application, which is outside your app and you have no control over it, create your own screen with a MapField in it. Using your own screen and perhaps extending the MapField class to override functions if needed, allows you to go back to the previous screen once the user selects a location.