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
New Developer
Posts: 14
Registered: ‎12-09-2008
My Device: Not Specified
Accepted Solution

Alert on non-ui application

Is it possible to use Dialog.alert() on non-ui, background processing application? I have tested on simulator but sadly it always freeze when the alert dialog appear (however alert dialog didn't appear but i can see it being called in JDE debugger) or maybe another approach?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alert on non-ui application

I think this KB article will answer your question.

 

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

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

New Developer
Posts: 14
Registered: ‎12-09-2008
My Device: Not Specified

Re: Alert on non-ui application

thanks for the answer Smiley Very Happy, i've missed good articles on KB
Developer
Posts: 168
Registered: ‎11-01-2008
My Device: Galaxy S II
My Carrier: Meteor (Ireland)

Re: Alert on non-ui application

In the last sentence of that linked article (just before the code block) it says "background application that extends UiApplication." I'm wondering if it shouldn't say "background application that extends Application." I mean, if your app extends UiApplication can't it just use UiApplication.pushModalScreen(), etc.? Or is the advantage of the suggested code that it gets around the problem of the app automatically exiting when the dialog is popped off the screen stack? 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Alert on non-ui application

This article is out of date.

 

Don't use UiEngine.queueStatus(). It has been deprecated since about 4.1.

 

Use UiApplication.pushGlobalScreen(). You should place the push in a Runnable and pass this to UiApplication.pushGlobalScreen(), if you extend UiApplication.

 

If you extend Application, then get a reference to the UiEngine and call its pushGlobalScreen().

 

 

 

 

 

 

Developer
Posts: 168
Registered: ‎11-01-2008
My Device: Galaxy S II
My Carrier: Meteor (Ireland)

Re: Alert on non-ui application

Thanks Rex. I was aware that queueStatus() is deprecated and I have been using pushGlobalScreen() instead. What I'm getting at is that the typo in the article (where it refers to UiApplication when it should say Application) undermines the whole point it is trying to make, which is that even a non-UI app extending Application can use Ui.getUiEngine().pushGlobalScreen() to display notifications. 
New Developer
Posts: 14
Registered: ‎12-09-2008
My Device: Not Specified

Re: Alert on non-ui application

[ Edited ]
Hi Rex,

i change queueStatus into pushGlobalScreen i use this code
 



private void notifyUser(String data) {
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, data, Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.VERTICAL_SCROLL);
//ui.queueStatus(screen, 1, true);
ui.pushGlobalScreen(screen, 1,UiEngine.GLOBAL_QUEUE);
}
public void locationUpdated(LocationProvider provider, Location location) {

/**
* Display the location fix if the fix is valid.
* Otherwise, display an error message.
*/
if ((location != null) && location.isValid()) {
QualifiedCoordinates coordinates = location.getQualifiedCoordinates();

if (past_coor != null) {
_distance = coordinates.distance(past_coor);
_distance = (double)(int)((_distance+0.005)*100.0)/100.0;
}
past_coor.setLongitude(coordinates.getLongitude());
past_coor.setLatitude(coordinates.getLatitude());

if (_distance > _accuracy) {
if ((coordinates.getLongitude() != 0) || (coordinates.getLatitude() != 0)) {
_url = "http://" + _host + "/gps/proc.asp?imei=" + _deviceID + "&lon=" + coordinates.getLongitude()
+ "&lat=" + coordinates.getLatitude();

try {
getViaStreamConnection(_url);
notifyUser("Send OK!");
} catch (IOException e) { notifyUser("Error: Network error"); }
} else{ notifyUser("Error: Coordinate was 0"); }
}
} else{ notifyUser("Error: Location invalid"); }
}

too bad it can't run now, did i make something wrong?

Message Edited by dels on 30-01-2009 07:47 PM
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Alert on non-ui application

If this code is not being executed in the UI event thread, then you will have to put your UI operations (like the push) in a Runnable (in the run() method) and pass it to invokeLater().
BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Alert on non-ui application

Thanks for the heads up, I'll have the article updated.  Can you elaborate on what is not working in your sample code?  Do you receive an exception?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 79
Registered: ‎02-19-2009
My Device: Not Specified

Re: Alert on non-ui application

Hello,

 

I tried it too. But I didn't get it working.

Here is my code:

 

 

	Application.getApplication().invokeLater(new Runnable() {
		public void run() {
			UiEngine ui = Ui.getUiEngine();
			Screen screen = new Dialog(Dialog.D_OK, "Look out!!!",
				Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
				Manager.VERTICAL_SCROLL);
			ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
		}
});

 

I use a background application, which starts a new thread. In this thread you will find the code above.

Why doesn't work it for me?

 

Thanks for any answer.