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

New Developer
Posts: 9
Registered: ‎09-13-2008
My Device: Not Specified
Accepted Solution

Display Dialog on powerUp()



I am building an app which does not have a GUI and runs in the background. The app utilizes PhoneListener to disconnect a call and create another in it's place. Since I have no GUI I am unable to send the required keystrokes to the phone application until after a dialog is displayed (either a Dialog, Application Permissions request, or changing the OptionsProvider). What I want to do is just pop a dialog up on startup so I can then inject my keystrokes to end the call.


Here is my code:



public class GVIntercepter extends UiApplication implements SystemListener { public static void main(String[] args) { // register an options provider GVIntercepterOptionsProvider provider = new GVIntercepterOptionsProvider(); OptionsManager.registerOptionsProvider(provider); // register a phone handler PhoneHandler phone_handler = new PhoneHandler(); Phone.addPhoneListener(phone_handler); GVIntercepter instance = new GVIntercepter(); // instance.enterEventDispatcher(); if( ApplicationManager.getApplicationManager().inStartup() ) { // Add a system listener to detect when system is ready and available. instance.addSystemListener(instance); } else { // System is already ready and available so perform your start up work now. // Note that this work must be completed using invokeLater because the // application has not yet entered the event dispatcher. instance.doStartupWorkLater(); } // Enter the event dispatcher. instance.enterEventDispatcher(); } //Invoked when the user is putting the device into a power off state. public void powerOff() { } //Invoked when the device has left the power off state. public void powerUp() { Application.getApplication().removeSystemListener(this); doStartupWork(); } //Invoked when the internal battery voltage falls below a critical level. public void batteryLow() { } //Invoked when the internal battery voltage has returned to normal. public void batteryGood() { } //Invoked when the internal battery state has changed. public void batteryStatusChange(int status) { } private void doStartupWork() { // Perform your start up activities here! Application.getApplication().invokeLater( new Runnable() { public void run() { Dialog.ask(Dialog.D_YES_NO, "Display?"); } } ); } private void doStartupWorkLater() { Application.getApplication().invokeLater( new Runnable() { public void run() { doStartupWork(); } } ); } public GVIntercepter() { } }


 I've tried just about everything to get the dialog to display and I am at a loss here. Any ideas?


I'd also be open to suggestions on being able to send keystrokes from a backgound app in the phone app and using PhoneArguments to place a call without displaying any prompt at all.


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

Re: Display Dialog on powerUp()

I've never though very seriously about doing anything like what you are trying to do, so I'm sorry this is not a complete answer to your questions.  Perhaps you can use these details to get a bit further though.


You say that your app is a background up, however you have extended UiApplication.  So your app is treated like it will display a screen to the user, however you never push a screen, so your application never gets pushed to the foreground.  You will find that, once you have started up with your current code, Your icon is available on the Task Switcher (ALT + ESC) and if you swap to your application, your dialog is there to be seen (on a white background like any UiApplication).  Try it and see.


You could replace your code in doStartupWork() with something like the following, so that you can actually see it at startup.  Try this, and then see what happens when you select your application using the Task Switcher after replying to your Dialog (note I use UiApplication rather than Application, just because the code you are invoking later does need a UiApplication to run.  Your code actually works because you are getting your own application, which currently extends UiApplication.  If you change it to extend Application instead, then you will not get a UiApplication....


UiApplication.getUiApplication().invokeLater( new Runnable() { public void run() { UiApplication.getUiApplication().requestForeground(); Dialog.ask(Dialog.D_YES_NO, "Display?"); UiApplication.getUiApplication().requestBackground(); } } );


I suspect that you really want to be a background application.  In that case you extend Application, rather than UiApplication.  Then, to bring something to the user's attention, you can use UIEngine, as documented here:

How To - Alert a user from a Background application
Article Number: DB-00407  



Alternatively, you can do what you are doing, stick your Phone Listener in place, then exit the UiApplication, so it is not in the Task Switcher.   Even though you have exited your UiApplication, your hook is still in place and can still do something. 


I've one more related point.


You are actually putting a Phone Listener in place.  When that Listener get control, it will be running as the Phone Application, not your Application.  This application has a GUI interface, so perhaps you don't need to use this Dialog' to get access to a GUI.


Sorry, as noted, I've never really looked seriously at doing anything like what you are doing, so I don't understand it all and perhaps you have this covered.  Bit I hope this helps.