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
Developer
samasrinivas
Posts: 49
Registered: ‎02-13-2009
My Device: Not Specified
Accepted Solution

Registering both PhoneListener and FolderListener in the same app

If I am anywhere in any of the blackberry applications, when I receive a phone call, I am able to display a popup after the call is answered for example. But if I receive an email, I am not able to display any popup screen even though I see the messagesAdded() getting fired and also the popupscreen is being invoked as I stepped through the debug.

 

The mechanism I use to display the popuscreen for both Phone and Email events is the same, but the Phone event works and not the Email event.

 

Here is what I am doing

 

Autostart invokes my main class

 

public final class myMain {
       
    private myMain() {
        try {
            Phone.addPhoneListener( new ConcretePhoneListener() );
            Store store = Session.waitForDefaultSession().getStore();
            store.addFolderListener( new ConcreteEmailListener() );
        }
        catch (Exception e) {
            //
        }
    }
   
    public static void main( String[] args ) {
        PimAssistantMain theApp = new PimAssistantMain();
    }
}

 

Now in my ConcretePhoneListener() this is how I am invoking the popup screen

 

public class ConcretePhoneListener extends AbstractPhoneListener {
   
    private void somePrivateMethod() {

UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {

UiApplication.getUiApplication().pushScreen(new PhonePopupScreen());

}
        });

}

 

the above code works, but

 

public class ConcreteEmailListener implements FolderListener {
   
    private void somePrivateMethod() {

UiApplication.getUiApplication().invokeLater(new Runnable() {

            public void run() {

UiApplication.getUiApplication().pushScreen(new EmailPopupScreen());

}

        });

}

 

the above code DOES NOT work for some reason in the sense that when new email arrives, I do not see the screen popup like the one for the Phone event does.

 

In  both EmailPopupScreen() and PhonePopupScreen(), I extend the PopupScreen and make sure the screen is in the foreground using the code below

 

protected void onObscured() {
        UiApplication.getUiApplication().requestForeground();
    }

 

Can anyone point me first of all if I am heading in the right direction and also explain this strange difference in behaviour for these 2 type of events and how to make the email event display a popup screen

 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Registering both PhoneListener and FolderListener in the same app

You dialog won't run because you are still in the context of the messages program.

 

One way around this is to send yourself a global event. Place your message object in the global event and catch it back in your own app context, then you can use invokeLater().

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Registering both PhoneListener and FolderListener in the same app

[ Edited ]

First off let me say I have NOT actually attempted to display a screen on an email listener, so this might not work, but I might be able to help.

 

First we must look at a couple of things:

 

UiApplication.getUiApplication()....

Remember that this gets a reference to the UiApplication that is running, not your application.  So if you are running in the phone listener you are running in the phone application, in the email listener, you are running in the email application.

 

protected void onObscured() {
    UiApplication.getUiApplication().requestForeground();
}

onObscured is called when the screen is covered up by another screen.  If it not displayed, it won't be called.  Assume it was displayed, and the obscuring screen was from the same application that displayed the screen, then the requestForeground() will not do anything, because the Application is still in the foreground.  If the obscuring Screen was from another application, then there is potential that this would effectively hide the new screen.  I think this is why you do it - see later.

 

These points aside lets talk about why it works for the phone and not email.  Easy I think.  The phone listener runs in the phone application, which of course is in the foreground when the phone is being used.  What the phone application does is put itself into the background when it finishes.  So if you push a screen to the foreground when the phone application is running it will display, but might disappear - hence I think the use of the requestForeground() in the onObscured().

 

However the email application runs in the background at the time of the listener invocation. so just pushing the screen is not going to get it on the screen.  So to get this screen displayed, the application must be set to the foreground.

 

I hope that has shed some light.

 

Now I would suggest, instead of pushing these screens using the actual RIM applications, pass this processing back to your own application, and then you have control over foreground/background processing.  Probably the best way to do this is to use a Global Event, extract the data you want from the listener, send this to your application, then process this in your own application.

 

Edit: Apologies for duplicating this suggestion - I was editing when RexDoug

Message Edited by peter_strange on 03-21-2009 12:52 AM
Please use plain text.
Developer
samasrinivas
Posts: 49
Registered: ‎02-13-2009
My Device: Not Specified

Re: Registering both PhoneListener and FolderListener in the same app

Thanks Peter & Rex, that really explained quite a lot of things and introduced me to the concept of Global Events which is a way of communicating between applications. I will try to incorporate into my current design and hopefully will get back with further questions if I get stuck again. Thanks again for your help, I greatly appreciate it for the quick response.
Please use plain text.