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
Regular Contributor
zumwaltwood
Posts: 81
Registered: ‎01-14-2011
My Device: Curve 8530
My Carrier: Cricket
Accepted Solution

onFocus() not firing between screen push/pop

	protected void onFocus(int args)
	{
		super.onFocus(args);
		invalidate();
		Dialog.inform("Screen refreshed test.");
	}

 

In my parent screen, I have this code which is not triggered either when the screen first loads up nor when subsequent screens are popped off the stack. I push to the stack screens based on menu options, when done, I pop them off the stack which in "theory" should mean the subsequent screen that is now visible has gained focus which should cause the onFocus to trigger, but it does not.

 

That code does nothing... So that being said, when the "parent" or "visible" screen gains focus, I need to simply redraw all controls and refresh some data, so which method do I use to determine that the screen is now the top of the stack and visible?

BlackBerry Java JDK 6.0.0.30
BlackBerry Java Plug-in 1.3.0.201101051005-15
BlackBerry JRE 6.0.0
Eclipse: Helios

Please use plain text.
Developer
jtp5120
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: onFocus() not firing between screen push/pop

Please read this post and answer by peter_strange:

http://supportforums.blackberry.com/t5/Java-Development/Screen-Life-Cycle-onDisplay-onUiEngineAttach...

 

Plus, take at look at:

onUiEngineAttached

protected void onUiEngineAttached(boolean attached)

Called whenever the screen is attached or detached from a UiEngine. Replaces onDisplay and onUndisplay.

 

Parameters: attached - true is it is an attach event, false if it is a detach event See Also: Screen.onExposed(), Screen.onFocusNotify(boolean) Since: BlackBerry API 4.3.0

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: onFocus() not firing between screen push/pop

The onObscured() / onExposed() pair is probably the most fitting place for checking this stuff. Can be replaced by onVisibilityChange(boolean).

 

However, unless you have some very custom paint override, don't bother invalidating - when the screen is first pushed, it is painted anyway; when all the screens above it get popped (so that it becomes the active screen again) it is also repainted (partially, if the popped screen was smaller than the full screen).

 

Ironically, scroll does not always cause the repaint - it seems that BlackBerry has some graphical buffers which are bigger than the screen; I found it out the hard way when I created a Windows-style scrollbar and saw it being royally screwed on touchscreen scrolling.

 

invalidate() is good in those cases when you change some flag or value affecting the appearance and want to force a repaint; otherwise, BB framework is quite good at managing those things on its own.

----------------------------------------------------------
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.
Regular Contributor
zumwaltwood
Posts: 81
Registered: ‎01-14-2011
My Device: Curve 8530
My Carrier: Cricket

Re: onFocus() not firing between screen push/pop

protected void onUiEngineAttached(boolean args)
{
	if(args)
	{
	invalidate();
	Dialog.inform("Screen refreshed test -  True.");
	}
}

 The problem with this is that it throws an error:

 

"Uncought exception: pushModalScreen called by a non-event thread"

And that is the only code I added, looking for the chain of events that needs to happen to make this work, that link you provided was a criptic discussion at best, no sample code and unfortunately the API just defines the methods and what the inputs and outputs are without example use cases.

 

BlackBerry Java JDK 6.0.0.30
BlackBerry Java Plug-in 1.3.0.201101051005-15
BlackBerry JRE 6.0.0
Eclipse: Helios

Please use plain text.
Developer
jtp5120
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: onFocus() not firing between screen push/pop

[ Edited ]

You need the Event lock to push a Modal screen. So you can synchronize on the event lock or run invokeLater or invokeAndWait methods.

 

UiApplication API:

 

Note that a UI application must follow rules similar to those of traditional Swing applications. In particular

  • Only one thread at a time (generally, the event-dispatching thread) may gain access to an interface component at once.

     

  • If you need access to the UI from outside event-handling or drawing code, then you can use the invokeLater() or invokeAndWait() methods.
--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: onFocus() not firing between screen push/pop

Stop using Dialog.inform (it is way too disruptive, especially for UI stuff that you are doing) and start logging events in some file.

 

Also, learn about the event thread and its importance here:

What is the event thread?

----------------------------------------------------------
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.
Regular Contributor
zumwaltwood
Posts: 81
Registered: ‎01-14-2011
My Device: Curve 8530
My Carrier: Cricket

Re: onFocus() not firing between screen push/pop

Dialog.inform, this is during initial design research and they are only there for instant information without the need to go look in log files for this immediate reponse, they all get removed after I test that one method. I will look into that link you provided to see if it has some enlightening information.

BlackBerry Java JDK 6.0.0.30
BlackBerry Java Plug-in 1.3.0.201101051005-15
BlackBerry JRE 6.0.0
Eclipse: Helios

Please use plain text.
Regular Contributor
zumwaltwood
Posts: 81
Registered: ‎01-14-2011
My Device: Curve 8530
My Carrier: Cricket

Re: onFocus() not firing between screen push/pop

[ Edited ]

Just for fun, I threw in a quick EditField, then created a log method to update that field, the onUiEngineAttached is thrown with true when the screen is first pushed onto the stack and the field is updated, when the next screen is pushed onto the stack then popped off the stack, the onUiEngineAttached is not thrown, which is back to the original problem that onFocus has.

 

private void log(final String msg) {
  UiApplication.getUiApplication().invokeLater(new Runnable() {
    public void run() {
      info.setText(info.getText() + "\n" + msg);
    }
  });
}

 

 

Then my onUiEngineAttached:

protected void onUiEngineAttached(boolean args)
{
  try
  {
    if(args)
    {
      log("Screen refreshed test -  True.");
    }
  }
  catch(Exception ex)
  {
    log("Error: " + ex.toString());
  }
}

 Problem is the POP of the screen off the stack, the current displayed screen needs to be redrawn, and even in this case, onUiEngineAttached is not thrown.

BlackBerry Java JDK 6.0.0.30
BlackBerry Java Plug-in 1.3.0.201101051005-15
BlackBerry JRE 6.0.0
Eclipse: Helios

Please use plain text.
Developer
jtp5120
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: onFocus() not firing between screen push/pop

  • onUiEngineAttached returns true only when a screen is pushed to the Display Stack.
  • onUiEngineAttached returns false only when a Screen is popped from the Display Stack.

 

  1. So if you push screen 1, then onUiEngineAttached is true.
  2. Then if you push screen 2 then onUiEngineAttached is true.
  3. Then if you pop screen 2 then onUiEngineAttached is false.
  4. Screen 1 onUiEngineAttached isn't false until it is popped off the stack.

 

I think you want Field.onVisibilityChange as mentioned above.

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Please use plain text.
Regular Contributor
zumwaltwood
Posts: 81
Registered: ‎01-14-2011
My Device: Curve 8530
My Carrier: Cricket

Re: onFocus() not firing between screen push/pop

onExposed works for my purposes, I get nothing from the onVisibilityChange, its dead for results.

As a test with my log in place this code updates the field, although the menu show / hide also triggers so I will need to make myself a dirty flag to use.

 

protected void onExposed()
{
  log("Screen exposed -  True.");
}
	

 

BlackBerry Java JDK 6.0.0.30
BlackBerry Java Plug-in 1.3.0.201101051005-15
BlackBerry JRE 6.0.0
Eclipse: Helios

Please use plain text.