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
Contributor
Posts: 27
Registered: ‎01-21-2011
My Device: Bold 9900
My Carrier: Cellcom
Accepted Solution

Show Dialog.ask when callDisconnected and wait for user to respond

Hey,

 

I'm using Dialog.ask when callDisconnected event fired, but the dialog appears only for couple of seconds and then disappears.

Is there any way to keep the dialog active until user will respond?

 

This is my code:



public void callDisconnected( int callId )
{ 
if( !caller.isIdentified() )
return;

Runnable runnable = new Runnable()
{
public void run()
{
if( Dialog.ask(Dialog.D_YES_NO, "Add " + caller.toString() + " to contacts?") == Dialog.YES )
{
addToContacts( caller.getFirstName(), caller.getLastName(), caller.getNumber() );
Status.show( caller.toString() + " is now a contact" );
}

caller = new Caller(); //Reset caller info.
}
};
UiApplication.getUiApplication().invokeLater(runnable);
}

 

B.T.W - If I'm using 'invokeAndWait(runnable)' instead 'invokeLater' the dialog disappears after couple of seconds, but when I'm opening the phone application I can see the dialog again - this time it won't disappear by its self..

 

Any ideas?

 

Thanks,

Rotem

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Show Dialog.ask when callDisconnected and wait for user to respond

This sort of thing is confusing, until you get your head around the fact that Listeners are often executed in the 'context' of the application that invoked them.  In this case, your Phone Listener is being invoked in the Phone Application, and one of the things that it does once a call is finished is put itself in the background.  As a result, your DIalog disappears, but will be there when the Phone application is bought to the foreground.

 

There are a variety of approaches to resolving this, depending on exactly what you are trying to do. 

 

In this case, I would suggest that you use a Global Event to context switch to your own application, and then push a Global Dialog to ask the question. 

 

You will find how to Global Events in this KB article:

http://supportforums.blackberry.com/t5/Java-Development/Global-Events-and-Global-Event-Listeners/ta-...

Contributor
Posts: 27
Registered: ‎01-21-2011
My Device: Bold 9900
My Carrier: Cellcom

Re: Show Dialog.ask when callDisconnected and wait for user to respond

Hey,
It seems a great solution, I am changing my code according to this event, although I have a question about GlobalEvent:
How do I determine the GUID?
Should I just choose a random value? What about conflicts with another application's GlobalEvent?

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

Re: Show Dialog.ask when callDisconnected and wait for user to respond

you can use the "string to long" function in eclipse to create a GUID
----------------------------------------------------------
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
Contributor
Posts: 27
Registered: ‎01-21-2011
My Device: Bold 9900
My Carrier: Cellcom

Re: Show Dialog.ask when callDisconnected and wait for user to respond

Hi,

@peter_strange - I tried to use global event as you said, but I think I misunderstood the way I should use global events.

 

This is the way I used the global event - what did I do wrong?


My main app class:


public class BesApp extends UiApplication
{

    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        BesApp theApp = new BesApp();       
        theApp.enterEventDispatcher();
    }
    
    public BesApp()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new HomeScreen());
        addGlobalEventListener( new CallerToContactsListener() ); // Adding the global event listener
    	Phone.addPhoneListener(new PhoneScreenContent());
    }    
}

 

callDisconnected on my PhoneListener class:

 

    public void callDisconnected( int callId )
    {   
    	if( caller.isIdentified() )
    	{    	
    		// GUID = com.rreiss.besId.CallerToContactsListener
    		ApplicationManager.getApplicationManager().postGlobalEvent(0xa2f09ac81056548bL, 0, 0, caller, null);
    	}
    }

 

 And last..

My global event listener:

 

public class CallerToContactsListener extends UiApplication implements GlobalEventListener
{
	public CallerToContactsListener()
	{
	}
	
	public void eventOccurred(long guid, int data1, int data2, Object caller, Object arg4)
	{
		// GUID = com.rreiss.besId.CallerToContactsListener
		if( guid == 0xa2f09ac81056548bL )
		{		
                      UiApplication.getUiApplication().invokeLater(new Runnable()
                      {
                           public void run()
                           {
                                addContact( (Caller)caller );
                           }
                      });
                }
	}
}

 

I also tried to replace my addContact method with Dialog.alert() and in both cases I get this:



 err.png

 

What am I doing wrong? :smileysad:

 

Thanks,

Rotem

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

Re: Show Dialog.ask when callDisconnected and wait for user to respond

don't extend UiApplication with your listener.
----------------------------------------------------------
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