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
justindutoit
Posts: 401
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
Please use plain text.
Developer
dnepr
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.

Please use plain text.
Developer
justindutoit
Posts: 401
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.
Please use plain text.
Developer
dnepr
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.

Please use plain text.
Developer
justindutoit
Posts: 401
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.
Please use plain text.
Developer
arkadyz
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!
Please use plain text.
Developer
justindutoit
Posts: 401
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.

 

Please use plain text.
Developer
jMarc
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.

Please use plain text.
Developer
arkadyz
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!
Please use plain text.
Developer
peter_strange
Posts: 19,601
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
}

Please use plain text.