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
Posts: 86
Registered: ‎01-09-2009
My Device: Not Specified
Accepted Solution

AbstractPhoneListener problem

I am trying to extend a AbstractPhoneListener.  I can implement it with no problem, it fires up when i simulate an incoming call, now I need to call a function from a different class that extends MainScreen, every time call comes in, i check a variable from the MainScreen class but the variable is a new instance of my MainScreen class.  I have tried static variable, outerclass.this.variable inside the inner class.  Nothing seems to be working.  I have also tried singleton class but that returned a new instance also....?? here's a snapshot of what i am trying to do:

 

 public class MyPhoneListener extends AbstractPhoneListener
{
    private MyScreen theApp;
    public MyPhoneListener(MyScreen screen)
    {
        theApp = screen;
    }

 public void callIncoming(int callId)
    {
        try
        {
            if (MyScreen.running == true)        //this line, running is not initialized and is null, its declared as static

           {
                MyScreen.escape();       
            }

/*

            if (theApp.running == true)        //this line, running is not initialized and is null
            {
                theApp.escape();       
            }

 

 

*/


        }
        catch(Exception ex)
        {
            System.out.println("Error incoming call.");
        }
        super.callIncoming(callId);
    }
 }

 

any ideas why this is happening?

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: AbstractPhoneListener problem

the phone listener runs in the context of the phone application (similar to having its own JVM).

You have several possible solutions:
- hand a reference of your main application to the phone listener. you can use invokelater on it for ui operations
- use global events to notify a separate app
- use runtime store to obtain a singleton instance

i guess your phone listener is not started by your application as you check for it running, this would leave 2 and 3 as options.
you can use the ApplicationManager class to check if your app is running.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 86
Registered: ‎01-09-2009
My Device: Not Specified

Re: AbstractPhoneListener problem

Thank Simon, i used the Runtime Store worked on first try.