Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Contributor
Posts: 5
Registered: ‎12-03-2010
My Device: Not Specified

ApplicationMenuItem.run receives a NULL context in OS6

[ Edited ]

Hi,

 

I am developing an application that registers an ApplicationMenuItem in the  MENUITEM_PHONE and the MENUITEM_PHONELOG_VIEW to launch an action over the item selected in the phone call log.

 

In version 5.0 all works fine, but in 6.0 (real Torch device and emulator) the run method receives a null object as context, so I have no data about the item selected by the user.

 

 

-----------------------------------------------------------------------------------------------------------------------

Tools:

 

Blackberry 8520 v5.0.0.592 (Platform 2.13.0.118)
Blackberry 9800 v6.0.0.141 (Bundle 278, Platform 3.0.0.60)

Eclipse 3.5 Build id: 20090920-1017
Blackberry Java Plug-in Version: 1.1.2.201004161203-16
Blackberry Java SDK version 5.0.0.25

 

-----------------------------------------------------------------------------------------------------------------------

Code:

 

Register the Item:

 

 

ApplicationMenuItemRepository amir =
ApplicationMenuItemRepository.getInstance();


amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONE,  
                MenuItemBuscarNumero.getInstancia());
       amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONELOG_VIEW,  
                MenuItemBuscarNumero.getInstancia());

 

 

The menu item

 

public class MenuItemBuscarNumero extends ApplicationMenuItem {

public static int DEFAULT_ORDER = 10;

private static MenuItemBuscarNumero _instancia;
private InternalLogger _log;


public static MenuItemBuscarNumero getInstancia() {
if (_instancia == null) {
_instancia = new MenuItemBuscarNumero(DEFAULT_ORDER);
}
return _instancia;
}

private MenuItemBuscarNumero(int order) {
super(order);
// TODO Auto-generated constructor stub
_log = new InternalLogger(Constantes.APP_NAME, Constantes.APP_GUID);
}

public MenuItemBuscarNumero(Object context, int order) {
super(context, order);
// TODO Auto-generated constructor stub

_log = new InternalLogger(Constantes.APP_NAME, Constantes.APP_GUID);
}

public Object run(Object context) { // <---- Version 6.0 receives NULL here
String number = null;
if (context != null) {
if (context instanceof PhoneCallLog) {
PhoneCallLog pcm = (PhoneCallLog) context;
number = pcm.getParticipant().getNumber();

boolean nuevoNumero = (pcm.getParticipant().getName() == null);

searchAndShow(number, nuevoNumero);
}
else {
if (context instanceof String) {
number = (String) context;
searchAndShow(number, true);
}
else {
// en la version 6 parece que viene un string
String txt = "Contexto desconocido " +
context.getClass().getName() +
" [ " + context.toString() + " ]";
log(txt);
System.err.println(txt);
}
}
}
else {
String txt = "Contexto desconocido valor NULL";
log(txt);
System.err.println(txt);
}
return context;
}

public String toString() {
return "Buscar Número";
}


public void searchAndShow(String number, boolean nuevo) {
... do something ....
}

public void log(String msg) {
try {
_log.logAlwaysEvent(msg);
}
catch (Exception ex) {
System.err.println("Internal Error [ " + msg + " ] " + ex.getMessage());
ex.printStackTrace();
}
}

}

 

-----------------------------------------------------------------------------------------------------------------------

 

 

Version 5.0 receives a PhoneCallLog object, but version 6.0 receives a String (if there is something in the dial box) or a null. I want to extract the number from a call record that is missing in the 6.0.

 

Is this a bug on the Torch device or I have missed something?

 

Thanks in advance

 

 

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: ApplicationMenuItem.run receives a NULL context in OS6

Known issue.

 

Works on some releases, sends null on others, sends a String with the phone number in some older releases.

 

Very uneven implementation. If you search the forum, you will find many reports of this. I bellieve that someone posted a work-around, getting the active screen object from the run() method of the menu item.