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
Ekansh
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm

Request Foreground from Background Thread

[ Edited ]

Hi All,

 

 

 

I have a background thread in which i am pushing global screen. In that popup screen i have two buttonfields.

So on button click..

i am doing UiApplication.getUiApplication().requestForeground();

to bring my application on the front.

 

But its giving exception   "ClassCastException".

 

Any suggestion how to bring my application to foreground on Button Click from Background thread Popup.

 

 

Thanks

Ekansh

 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Request Foreground from Background Thread

Is your Background application an Application or a UiApplication?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Request Foreground from Background Thread

most likely not.

send a global event to your uiapplication and it can do the requestforeground itself

----------------------------------------------------------
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
Developer
Ekansh
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm

Re: Request Foreground from Background Thread

Hi,

Thanks for the reply.

 

@Peter: It extends from an Application.

 

@Simon: I am working on your suggestion and will let you know.

 

Regards

Ekansh

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Ekansh
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm

Re: Request Foreground from Background Thread

Hi Simon,

 

I implemented the GlobalEventListener as follows:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is...

 

 

But it works good if my UiApplication is in running mode.

 

 

If not, it doesn't work i.e. eventOccurred() methods are not called.

 

In this my background application extends from Application.

And the Ui is extends by UiApplication.

 

 

Please Help!.

 

 

Thanks

Ekansh

 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Request Foreground from Background Thread

you can use applicationmanager to determine if your app is running and, if not, launch it

----------------------------------------------------------
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
Developer
Ekansh
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm

Re: Request Foreground from Background Thread

Hi Simon,

 

Thanks..i am not able to detect and launch my application....please show some light.

 

public abstract void launch(String url)

 

I want to open my application on the click event of the button of the pop-up from the background thread.

 

 

Thanks

Ekansh

 

 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Request Foreground from Background Thread

use runApplication

----------------------------------------------------------
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
Developer
Ekansh
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm

Re: Request Foreground from Background Thread

Hi,

 

 

I did the follwing code on click.

 

 

try
                                    {
                                        int moduleHandle = CodeModuleManager.getModuleHandle("DataMonitor");
    
                                        if (moduleHandle != 0)
                                        {
                                                ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(moduleHandle);
                                                ApplicationManager.getApplicationManager().runApplication(apDes[0]);
                                        }
                                    }
                                    catch(Exception e)
                                    {
                                    }

 

 

it gives the follwing in output window:

 

Starting DemoApp
DemoApp already running

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Request Foreground from Background Thread

check if your ui app runs.

if yes, send global event

if not, start it (maybe using a parameter to let it do something special)

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