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
New Developer
nkumar
Posts: 13
Registered: ‎07-15-2008
My Device: Not Specified

Not able to show new fields when app is in the background

Hi,

 

In my application, i am showing some EditField, LabelField, and ButtonField on my MainScreen. Now because of some event my app goes into background and start observing some events while remaining in background.

Now on certain event my app removes existing fields from the MainScreen adds new fields to display while remaining in background. Subsequently i go to my app and click it to bring it in foreground. I still see previous fields on the MainScreen which were shown before my app went into background.

 

I am using deleteAll() method of Manager to delete all fields before adding new fields and doPaint() method of Screeb to paint all fields again. But my logic is not working.

 

Can someone through some light on what may be the problem ?

 

regards,

-nitin

 

 

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

Re: Not able to show new fields when app is in the background

What you are doing seems reasonable, though I'm not sure about the doPaint(), why would you bother when the screen is in the background? 

 

I would do some very thorough debugging to make sure the problem is not in your code.  I would specifically check that you don't have two instances of your screen (which is how I've seen this problem in my own code), and that the code you run in the background works when executed from a menu (i.e. in foreground).

Please use plain text.
Administrator
MSohm
Posts: 14,313
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Not able to show new fields when app is in the background

Depending on where you are calling the update from, you may want to use invalidate instead of doPaint.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
nkumar
Posts: 13
Registered: ‎07-15-2008
My Device: Not Specified

Re: Not able to show new fields when app is in the background

invalidate also doesn't work.

 

I am changing fields on the screen when i receive phonecall events in my listener class. And i don't think there are two different instances of my screen being created because i am able to show a Dialog.alert pop message on the screen from my background app but within same method when i can change fields they are not reflected.

 

regards,

-nitin

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

Re: Not able to show new fields when app is in the background

I take it that you can reproduce this problem easily on the Simulator? 

 

You make the comment that you don't have two different instances because you see the Dialog.  I don't think that proves that you don't have two instances.  I would put a debug point in when the Fields are being updated, and note the Screen Object referenced there (note the @... value).  I would also put a debug point in your display code somewhere, and make sure that the screen there is the same @... value.

 

Have you tried my second suggestion, to prove that the code you run in the background works when executed from a menu (i.e. in foreground)?  You will probably need to comment out your real, callLog interrogating code and put in some dummy code, say to just add a new label with the current time in it, but I think this would be a useful test.

 

You may not be aware, but the Listener call runs under control of a different Application than yours.  I must admit that I have never tried updating Screens belonging to one Application, from a different Application, which is effectively what you are doing.  Perhaps this results in an Exception, presumably an IllegalStateException.  Have you checked that you don't get any exceptions in your Phone Listener code?  Perhaps you could move the Dialog so that it is the last thing the code does - then if you get an exception, you won't see the Dialog, which makes it easy to test.

 

Finally, I must add that I have never had a problem like this (and I've had a few) that wasn't actually something in my own code.  But in case it is OS Level specific, can you tell me what level of JDE you are using.  Again, I'm assuming that you can reproduce this on the Simulator.

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Not able to show new fields when app is in the background

listener threads sometimes have to synchronize on the event thread of the application. if you use the common UiApplication.getUiApplication in a phone listener you would get the phone application, for example, as it is associated.
publish invokelater or getEventLock() from your application instance using a service and you can use it from outside.

other possibilities are putting the application into the runtime store to access public methods, using global events to notify the application to do something or run an alternative entry point (which is a bit dangerous because you can get multiple instances as the static context is not shared between AEPs).

i hope my post is understandable, don't hesitate to ask (or correct me, if i am wrong) :smileyhappy:
----------------------------------------------------------
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.
New Developer
nkumar
Posts: 13
Registered: ‎07-15-2008
My Device: Not Specified

Re: Not able to show new fields when app is in the background

Hi Peter,

 

i am not able to test my app on simulator as i am having another issue which i have been discussing on the other thread of this forum

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=1143&jump=true#M1143

 

But i did check by moving Dialog statement at the end. And your understanding is right, i didn't see the dialog this time. So may be there is some exception. 

 

So how do i see the exception on device and more importantly how do i change field from the listener's code if its being executed in someother thread?

 

Thanks Peter, i am glad that i have started seeing some dim light at the end of the tunnel :-)

 

regards,

-nitin

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

Re: Not able to show new fields when app is in the background

You should see the Exception in the Device's Log.  You can see the log by going to the Home Screen, then holding the ALT key down and pressing "L", then "G", then "L", then "G".  Then release the Alt key and you should see a list.  You can scroll down this list, Exceptions are normally listed in Bold.

 

Alternatively debug this by attaching the Device to the PC you have the JDE on, and then attach the device to the JDE (Debug Menu, select Attach To, then USB, then the device).  This may actually allow you to step through the code.  If you don't have a 'try catch', it will also display the Exception.

 

Alternatively, do this the hard way and put a number of load of "try catches" around each of the bits of code that were after your Dialog and are now before.  In the catch, put in an output statement like

System.out.println("just done <put in here the statement> and got exception: " + e.toString);

You will see this in the JDE Debugger window.  Or you could display a Dialog with the Exception details in it.

 

You should, using one of the above methods, be able to find out the error and the line it occurs on.  Then see if you can fix it!

 

How do you change into your own application to update the Field?  I run a thread in my own UiApplication. 

To do this I have to add a reference to my UiApplication in RuntimeStore, then just do something like:

UiApplication myUiApp = <Reference from RuntimeStore>;

myUiApp.invokeLater(.<code to update my Fields>.);

 

Hope that makes sense.

Please use plain text.