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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
dels
Posts: 14
Registered: ‎12-09-2008
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?
Please use plain text.
Developer
peter_strange
Posts: 17,631
Registered: ‎07-14-2008

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/...

Please use plain text.
New Developer
dels
Posts: 14
Registered: ‎12-09-2008

Re: Alert on non-ui application

thanks for the answer :smileyvery-happy:, i've missed good articles on KB
Please use plain text.
Developer
davidmccormack
Posts: 168
Registered: ‎11-01-2008
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? 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008

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().

 

 

 

 

 

 

Please use plain text.
Developer
davidmccormack
Posts: 168
Registered: ‎11-01-2008
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. 
Please use plain text.
New Developer
dels
Posts: 14
Registered: ‎12-09-2008

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
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008

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().
Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
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.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Developer
H3llGhost
Posts: 67
Registered: ‎02-19-2009

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.

Please use plain text.