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
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Subscribing to 'Switch application' event

Hi all.

It surprised me to find out that the Switch Application handling does not 'tick' the onScreenUiEngineAttached event.

I added a listener like this:

fSomeAppScreen.addScreenUiEngineAttachedListener(new ScreenUiEngineAttachedListener()

{

public void onScreenUiEngineAttached(Screen aScreen, boolean aIsPushedToForeground)

{

if(aIsPushedToForeground)

{

//Do something wild :) goWild();

  }

}

});

 

 But this didn't work with the Switch Application.

The  goWild() was triggered only two times: on first screen appearance, and on final closure of the application. The Switch Application (to and from) home screen did not fire up the event.
I do understand I should probably use onExposed() and onObscured() but these have protected access.
I also must point out that I don't have access to targeted screen's implementation so I can only use public interface.

Is there any solution on how to register to Switch Application's go to foreground/background action ?

Example:
My app 1 and 2 are running. App 1(background app) targets the screen of app 2 (they exchange references).
Now, when the User activates Swich Application and goes to Home screen, the app 1 would like to be notified.
Similarly, when the user switches back to app 2, the app 1 needs to know that.

As I said, I have full control over app 1 and none over app 2 (except it's reference and the reference of the targeted screen - only one)

Can this be done ?

Thanks

 PS. I know I could use a watcher thread approach to see whether the app 2's screen is displayed or not, but this consumes resources and is not as prompt as I require it to be.


"Listen carefully, I shall say this only once"
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Subscribing to 'Switch application' event

Switch Application is bringing your application to the Foreground, so triggers the activate() method in the UiApplication.

 

Since you have no control over App2, I'm not sure how helpful this information will be. 

Please use plain text.
Developer
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Subscribing to 'Switch application' event

Thanx for your interest, but I cannot subscribe to activate() :smileysad:

 

So I will not be notified when the User swithces back to the app2 screen.

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Subscribing to 'Switch application' event

I also tried this approach:

 

targetedScreen.getFieldWithFocus().setFocusListener(null);

targetedScreen.getFieldWithFocus().setFocusListener(new FocusChangeListener()

{ public void focusChanged(Field aField, int aEventType) {

  // TODO: accept only focus gained (to indicate return to this screen)

goWild();

} });

 But it didn't work either.

 

It seems that focus is not touched  when the screen(app) is pushed/popped from/to background/foreground.

 

Any hints on this approach?

 

 



"Listen carefully, I shall say this only once"
Please use plain text.