10-09-2009 03:19 AM
Hello all!
please help me on the following problem. i created an application which is working in background at the startup. i want to push a screen when any phone call is disconnected. i have added a phonelistener and wrote callDisconnected(callId) method. this method is called when the call is disconnected which is fine, but the problem is that no screen is displayed after the call disconnect. below is the code i am using for it.
============ Phone Listener ===============
public class CustomPhoneListener extends AbstractPhoneListener{
private Main theApp;
private PhoneCall call = null;
public CustomPhoneListener(Main theApp){
this.theApp=theApp;
}
public void callConnected(int callId) {
call = Phone.getCall(callId);
}
public void callDisconnected(int callId){
if(call != null){
System.out.println("???????-------Call Disconnected");
theApp.requestForeground();
theApp.invokeLater(new Runnable(){
public void run(){
System.out.println("???????-------Inside RUN");
theApp.pushScreen(new TagScreen());
}});
}
}
============ Main Class ===============
public class Main extends UiApplication {
private static Main theApp = null;
private Screen fScreen = null;
private static CustomPhoneListener customPhoneListener ;
public static void main(String[] args) {
if ( args.length == 1 && args[0].equals( "autostartup" ) )
{
// Create and register the object that will listen for Phone events. Check for
// ControlledAccessException as per page 69 of the BlackBerry Application
// Developer Guide, Volume 2 (Version 4.0).
try
{
theApp = new Main();
}
catch ( ControlledAccessException e )
{
Dialog.alert( "Access to Phone API restricted by system administrator." );
System.exit( 1 );
}
}
else /* THIS PART IS WORKING FINE */
{
theApp = new Main(new MenuScreen());
theApp.enterEventDispatcher();
}
customPhoneListener = new CustomPhoneListener(theApp);
Phone.addPhoneListener(customPhoneListener);
}
public Main(Screen screen){
pushScreen(screen);
}
public Main(){
}
}
================= Tag Screen ==================
public class TagScreen extends MainScreen {
private LabelField labelField;
public TagScreen(){
setTitle("Tag Screen");
labelField = new LabelField("Hello champ!");
add(labelField);
}
}
Solved! Go to Solution.
10-09-2009 03:44 AM
10-09-2009 04:13 AM
- start the app in your autostart part (i do this with my app, for example). a user click on the icon will bring it to the foreground
how will i trap the click on icon. moreover i have different screens let say, SCREEN_1 which is opened when clicked on icon and SCREEN_2 which i want to open when a call is disconnected.
i will really appreciate if i can get some piece of code. so that it is easy to understand the things.
10-09-2009 04:15 AM
10-09-2009 04:24 AM
10-09-2009 06:15 AM
10-13-2009 02:19 AM
Thank you very much Simon and Klyubin.
it worked when i added EventDispatcher properly. so now my main class looks sumthing like the following:
public class Main extends UiApplication {
private static Main theApp = null;
private static CustomPhoneListener customPhoneListener ;
public static void main(String[] args) {
if ( args.length == 1 && args[0].equals( "autostartup" ) )
{
// Create and register the object that will listen for Phone events. Check for
// ControlledAccessException as per page 69 of the BlackBerry Application
// Developer Guide, Volume 2 (Version 4.0).
try
{
theApp = new Main();
}
catch ( ControlledAccessException e )
{
Dialog.alert( "Access to Phone API restricted by system administrator." );
System.exit( 1 );
}
}
else
{
theApp = new Main(new MenuScreen());
}
customPhoneListener = new CustomPhoneListener(theApp);
Phone.addPhoneListener(customPhoneListener);
theApp.enterEventDispatcher();
}
public Main(Screen screen){
pushScreen(screen);
}
public Main(){
}
}
hope it helps other to solve the same problem.......
04-29-2011 03:41 AM
04-29-2011 03:50 AM
klyubin wrote:
To be more precise, immediately after you register the PhoneListener on startup, your application terminates (main() method returns). So, your listener has a reference to an application that is no longer running. Posting an invokeLater to the application won't achieve what you want because the application is no longer running (in particular, as simon_hain said, the event dispatcher is no longer processing events posted to the application).
while the practical difference is quite small i have to correct you here.
the phone listener has the phone application as the referenced uiapplication, and when you use getActiveScreen you get a reference to the PhoneScreen.
This also happens when you register the listener in your own UiApplication which is still alive.
You can give the phone listener a reference to your UiApp, or use runtimestore or global events to move the execution context to your instance.
It is a bit surprising, but also helpful if you want to meddle with the phone app ![]()