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
Developer
Afzal
Posts: 31
Registered: ‎06-12-2009
My Device: Not Specified
Accepted Solution

Show a Dialog Box from non event thread

I need to show a Dialog box from an alternate entry point (when a push message arrives).

 

To do this I need to create an Application instance from alternate entry point and listen for incoming push.

 

The problem is when I extend my application class from UiApplication, and calls enterEventDispatcher(); from the alternate entry point it shows an application icon in running applications forever (seen by holding menu button).

 

I need to listen for push messages and alert user by a dialog without having an application icon.

 

So is there any way I can show a dialog from alternate entry point without an UI event thread ? if no, then whats the use of push if you cannot alert the user?

 

Please help. Stuck!

 

Thanks in advance.

Afzal

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Show a Dialog Box from non event thread

You could create an Application instance (instead of a UiApplication), and then use this:

 

http://supportforums.blackberry.com/t5/Java-Development/Alert-a-BlackBerry-smartphone-user-from-a-Ba...

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Show a Dialog Box from non event thread

Options:

1. Use global dialogs/screens. UiEngine.pushGlobal...

2. Make sure your UiApplication returns false from its acceptsForeground method.

3. Use Application instead of UiApplication and then use Ui.getUiEngine().push... Not 100% sure if this'll work.

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Show a Dialog Box from non event thread

[ Edited ]

3. WIll work

2. I think this can be problematic, because until you return true from acceptsForeground, your Dialogs won't be shown either.

1. Not sure of the difference between 1 & 3...

 

Do you really need an alternate entry to listen?  Can't you start a Thread off your main Application?

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Show a Dialog Box from non event thread

 


peter_strange wrote:

 

Do you really need an alternate entry to listen?  Can't you start a Thread off your main Application?


 

One of the big considerations in implementing Push on pre-5.0 platforms is the ability (or, rather, inability) to listen for Push messages when the application is not running (and, IMHO, shutting down your application is a very polite thing to provide).

 

In this case, running an Application (which will use a lot fewer resources) at startup is a sensible way of ensuring that your main application will get push notifications no matter what.

When your "push listener" application gets a message, it might decide to store it in a PersistentStore for the main one to use later, or check whether the main application is running and post it a global event, or, when the main one is not running, even start it with some specialized arguments indicating that the application was invoked because of a Push message arriving.

 

If you do it like that, delegate your popup pushing to the main application.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Show a Dialog Box from non event thread

Displaying a global dialog/screen is better because it's easier to ensure that it's visible to the user (if you display a conventional dialog it will only be visible if the app is in the foreground). Also, once the global dialog/screen is dismissed, the flow returns to whatever app was in the foreground when the dialog appeared, instead of the app that pushed the global dialog.

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Show a Dialog Box from non event thread

I do understand the requirements for Push listeners pre OS 5.0.  . 

 

I don't really understand why starting a UiApplication, as compared with an Application, is such a big resource hog.  I've not done a detailed examination of the extra weight of the UiApplication over the Application, but it doesn't feel significant to me.

 

And I think this using a UiApplication has advantages, especially as you can display a 'UI' for the push processing, provide the user a way of restart it and so on. 

 

So given that I think the Push listener could be a UiApplication rather than just an Application, then the question is, why have two UiApplications?

 

There are complications when running two separate UiApplications, that are reduced if they are in fact the same thing.  For example, in your push listener, you can run things on the Event Thread, knowing that the 'main application' is not also doing the same thing at the same time.  You don't need RuntimeStore to share stuff - you can use Application Storage.  If you want to start one specific screen display, you don't have to invent some special invoke logic to get there. 

 

Of course there is a downside.  And that is to have to careful in your single application that you don't exit, that you don't leak storage, and you tidy up all the resources you use.  But I suspect that these are less involved and/or you should do it anyway than having separate applications.  There are a number of RIM BlackBerry applications that just go to background and don't actually close. 

 

However this is my opinion only, there is not one right answer here.  I would only ask that you do not dismiss the single UiApplication model out of hand. 

 

Not sure I agree with klyubin's comments either.  Foregrounding the Application to make sure the Dialog is displayed is no more intrusive than a global Dialog.  There are restrictions on things you can't do/display using Global Dialogs (try displaying a DateField that the user can change on one for example).  In the display, you can give the user the option to process the message (in which case they are probably already in the right place) or not, in which case the app can background itself and the user can return to whatever was in progress, just the same as a Global Dialog. 

 

There are other ways to let the user know that something has arrived too. 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Show a Dialog Box from non event thread

 


klyubin wrote:

Displaying a global dialog/screen is better because it's easier to ensure that it's visible to the user (if you display a conventional dialog it will only be visible if the app is in the foreground). Also, once the global dialog/screen is dismissed, the flow returns to whatever app was in the foreground when the dialog appeared, instead of the app that pushed the global dialog.


There is a much better and universally accepted way - use NotificationsManager to blink LED, vibrate and/or play a sound.  If you are aiming at 4.6+ devices, the top notification ribbon is also available.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.