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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 512
Registered: ‎05-31-2009
My Device: Not Specified
Accepted Solution

Add a field to a Screen more than once

Hey. Just want to add the same field to a Screen many times without an IllegalStateException (meaning the field already has a manager). Code is as simple as myScreen.add(myfield); many times. Workaround? Cheers
Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Add a field to a Screen more than once

You have to clone the field to be able to do that.

 

Create a new instance and populate with same parameters as the old.

Developer
Posts: 512
Registered: ‎05-31-2009
My Device: Not Specified

Re: Add a field to a Screen more than once

Hey tks. No the reason I am doing it is that I want to add >10 objectlistfields to a MainScreen almost instantly. They are created, populated etc which is slow. Then they go into the runtimestore and are retrieved quickly. Works great. Is there a workaround if the user exits the app and reopens and I need to add them again? Strange, I take them out of the store and add them but don't put them back I think. But there it is, their manager is set when I try to repeat. Appreciate your time, Justin.
Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Add a field to a Screen more than once

You can delete them from their manager before adding them again to a new manager.

Developer
Posts: 512
Registered: ‎05-31-2009
My Device: Not Specified

Re: Add a field to a Screen more than once

Hi. Before I add the fields I do a myscreen.deleteAll();
No good?

J.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Add a field to a Screen more than once

Depending on whether your Fields are added to a Manager or directly to myscreen. If that manager is referenced by something it will not be garbage collected and your fields will still be managed by it. Not being on the screen stack does not mean not being managed.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 512
Registered: ‎05-31-2009
My Device: Not Specified

Re: Add a field to a Screen more than once

Hey. This is the code:

 

                        m_everyOLF = GetEveryOLFFromRuntimeStore();
                        m_sharpRSSMainScreen.deleteAll();

                        for (int i = 0; i < m_feeds.length; i++) {
                                
                                  SRSS_OLF myOLF = (SRSS_OLF)m_everyOLF.elementAt(i);
                                  m_stunningRSSMainScreen.add(myOLF);  //// myOLF is an extended ObjectListField
                        }  

 

It works the first time the app runs, but when the mainscreen goes to get recreated, it gets the illegalstateexception.

 

Cheers.

 

Developer
Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

Re: Add a field to a Screen more than once

To expand on arkadyz's comment, the API Javadocs say:

 

MainScreen is a subclass of Screen, which is a subclass of Manager.

MainScreen inherits add and delete from Screen. It inherits deleteAll from Manager.

The Screen add method invokes add on the Screen's delegate Manager.

The Screen delete method invokes delete on the Screen's delegate Manager.

The Manager deleteAll method removes all fields from the Manager.

 

Got all that?

 

So when you invoke add or delete on MainScreen, you are adding to and deleting from the MainScreen's delegate Manager.  But when you invoke deleteAll, you are deleting fields from the MainScreen itself -- which probably doesn't actually have any fields.  All those fields you think you are deleting are still managed by your MainScreen's delegate Manager.

 

So your work around is to loop through the fields you added, deleting them one at a time.

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Add a field to a Screen more than once

I guess the problem is that the code does not invoke

m_stunningRSSMainScreen.deleteAll();

before going back to the "sharp" screen...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Add a field to a Screen more than once

I guess this is just to hokey to even be considered....

 

for (int i = 0; i < m_feeds.length; i++) {
    SRSS_OLF myOLF = (SRSS_OLF)m_everyOLF.elementAt(i);
    if ( myOLF.getManager() != null ) {
        Manager m = myOLF.getManager();
        m.delete(myOLF);
    }
    m_stunningRSSMainScreen.add(myOLF);  //// myOLF is an extended ObjectListField
}