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
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified
Accepted Solution

Pushing global screen message from a background uiapplication

 

I have an uiapplication, that has an user interface with main menu, mainscreens and stuff, but it also runs on startup, in order to keep listening for updates. I set an entry point to it, then I may push the gui when I want.

 

And I want to notify the user, with a simple dialog screen, when theres updates and ask if he wants to launch the application (gui).

 

The problem is: I want the dialog over the homescreen, as a simple notification, but I couldn't, since I'm trying to pushGlobal from the uiapplication on background, and even if I get the Ui.getUiEngine(), it returns the uiapplication uiengine, and then it only shows if I enterEventDispatcher(), with a blank background.

 

I can't extend Application just to show the dialogs, since my application does have gui.

 

I think I may need to create two applications, one extending Application, to handle the background listener and to be able to pushglobal dialogs over homescreen, and another extending UiApplication, that may be called from the first one.

 

Is there another approach? Is it possible to pushGlobal dialogs over homescreen from a uiapplication?

 

I searched a lot but I didn't find anyone that wanted to do what I need. Actually I think I'm going on the wrong way so I expect someone will have the answer to my problem.

 

 

 

 

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: Pushing global screen message from a background uiapplication

Ok, this is what I want to do:

 

    public static void main(String[] args) {
        
        MyUiApplication myApp = new MyUiApplication;
        

        //I have an entry point for this
        if (args.length > 0 && args[0].equals("gui")) {
            myApp.showGui();

            myApp.enterEventDispatcher();
        } else {


           // if I do this, the app never shows up.

           // myApp.enterEventDispatcher();

 

            //start background thread
            while(true)
            {
                try {
                    Thread.sleep(180000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                

                //if there's updates, notify the user
                if(myApplication.hasUpdates())
                {
                    Dialog dialog = new Dialog(Dialog.D_OK, "You have updates!",
                            Dialog.OK, Bitmap
                            .getPredefinedBitmap(Bitmap.EXCLAMATION),
                    Manager.VERTICAL_SCROLL);
                    //dialog notification over homescreen or anything
                    myApp.pushGlobalScreen(dialog, 1, UiEngine.GLOBAL_QUEUE);

 

                    //later I'll add a listener here and the user will be able

                    //to launch the app if he wants to check the updates

 

                }     

 

                // if I do this, the app shows once

                // myApp.enterEventDispatcher();

          
            }
        }        
    }

 

Gosh, this is so stupid! There must be a way to do it!

 

I already did the dialog to be shown over homescreen pushing it right before calling enterEventDispatcher(). But I could not show it again after that. Looks like when I got the dialog shown once, if I close it the app stops. I tryed overriding it's close() method to just pop it and requestBackground(), and requestForeground() again when I need it, but that didn't work.

 

UiApplication just seems not to fit as a background app..

 

HELP!



Please use plain text.
Developer
simon_hain
Posts: 16,214
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Pushing global screen message from a background uiapplication

extend application, not uiapplication. with hfm being an horizontalfieldmanager:

 

Ui.getUiEngine().pushGlobalScreen(new PopupScreen(hfm) , 1, UiEngine.GLOBAL_QUEUE);

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: Pushing global screen message from a background uiapplication

So, as I thought, the solution was quite simple.

 

I created another class that extends Application and when I want to start the background listener, instead of instantiating my UiApplication I just instantiate that class, which looks like this:

 

public class BackgroundListener extends Application{

    public void startBackgroundThread()
    {
        new Thread(){
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(180000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                    //do my logic  

 

                    synchronized (getEventLock()) {

                        //with this UiEngine I'm able to pushGlobal dialogs

                        //whenever I want with the app in background

                        UiEngine ui = Ui.getUiEngine();
                        Screen screen = new Dialog(Dialog.D_OK, "You have updates!",
                                Dialog.OK, Bitmap
                                        .getPredefinedBitmap(Bitmap.EXCLAMATION),
                                Manager.VERTICAL_SCROLL);
                        ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
                    }
                }
            }
        }.start();
    }
}

 

And my main method ends up like this:

 

    public static void main(String[] args) {

        if (args.length > 0 && args[0].equals("gui")) {
            MyUiApp app = new
MyUiApp();
            app.showGui();
            app.enterEventDispatcher();
        } else {
            BackgroundListener app = new BackgroundListener();
            app.startBackgroundThread();            
            app.enterEventDispatcher();
            
        }
    }

 

Thanks for listening! lol

 

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: Pushing global screen message from a background uiapplication

simon, thanks for your reply, I actually have read other posts from you that had already helped me. :smileyhappy:

 

But my application IS an UiApplication. I need it to be. The problem was that I take too much time to figure out that I could have another Application under the same project and instantiate it to handle the background thread instead of my UiApp.

 

That's ok now, thank you very much.  :smileytongue:

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Pushing global screen message from a background uiapplication

Hi Simon,

How can i push screens from user clicking the button on that dialogbox.

how can i do that means.

 

i am pushing a global dialog box..

when user pressing ok then i am taking user into my app.

 

how can i handle that events.

Please use plain text.
Developer
simon_hain
Posts: 16,214
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Pushing global screen message from a background uiapplication

please open an own thread for your question. many people don't access threads marked as solved.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Pushing global screen message from a background uiapplication

k Simon,

i will place a new Thread.

Please use plain text.
Developer
avinash_kumar_ispg_in
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve

Re: Pushing global screen message from a background uiapplication

[ Edited ]

hi me also looking to open  the app while clicking ok on push popup.

 

 if any one got the solution please reply me .

thanks

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch

Re: Pushing global screen message from a background uiapplication

Use GlobalEventListener to handle that action.

 

search on the forum to how to use. or check samples

Please use plain text.