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
Contributor
Posts: 33
Registered: ‎06-16-2010
My Device: Blackberry 8520
My Carrier: Rogers
Accepted Solution

How to stop ObjectChoiceField prompting out save window???

Hi, I have 3 ObjectChoiceFields in my code to let user choose the information, then it will pass the value to the next new screen. However when i click the back key to go back to the previous screen and exit the app, it always prompts a notice window to ask me if I want to save, discard or cancel. If I click save, and run the code again, the ObjectChoiceFields still shows their initial value, so the save doesn't really work. I would like to know how can I make the save work, so that the next time I run the code, it will present the values I chose last time. or another solution, how should I stop ObjectChoiceField  prompting out save window?

 

Thanks a lot!

Regular Contributor
Posts: 68
Registered: ‎03-17-2010
My Device: 9000,9500,8900
My Carrier: Airtel,Vodafone

Re: How to stop ObjectChoiceField prompting out save window???

Hi

There are two ways to do this (assuming that stopping save prompt will solve the problem)

 

1.

In api use onSavePromptMethod();

 

This method is a member of screen class (AFAIK). you can override this and simply return true;

That  can not let the application show the save prompt

 

2.

 

Use this code first in onClose method

 

if (getMainManager().isDirty()) {
                getMainManager().setDirty(false);
            }

 

I've found that 2 always works and not sure about 1. But I prefer to use 1 and asking you to try this and tell whether this worked on your side or not....

 

 

Developer
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: How to stop ObjectChoiceField prompting out save window???

prash_bb_dev, 

good job. Personally didn't know about the 2 variant.

Confirm that 1 solution is working.

Got resolved! Press kudo icon!
Regular Contributor
Posts: 68
Registered: ‎03-17-2010
My Device: 9000,9500,8900
My Carrier: Airtel,Vodafone

Re: How to stop ObjectChoiceField prompting out save window???

Thanks @sonicboomboy

 

well I can say that 1 is working but AFAIK it's not called when no FieldChangeListener is called. Coz once i had implemented 1 and called a method inside onSavePrompt that checks for an image. and when i didn't change any field value that method was not called.

 

And i want to know whether my assumption here is true or not??

 

 

Developer
Posts: 106
Registered: ‎06-18-2009
My Device: Bold

Re: How to stop ObjectChoiceField prompting out save window???

If you want to save your selection on close, you need to persist it yourself.  The controls dont do it. 

 

If you only have one screen, you could override the close method -> save your values then call super.close() so that your application actually gets closed. 

 

 

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Developer
Posts: 45
Registered: ‎06-23-2010
My Device: Not Specified

Re: How to stop ObjectChoiceField prompting out save window???

You could also keep the reference to that field in your screen, and call setDirty(false) on it explicitly in onClose() method in case when you don't want to loose the "dirty" state in other fields.

Contributor
Posts: 33
Registered: ‎06-16-2010
My Device: Blackberry 8520
My Carrier: Rogers

Re: How to stop ObjectChoiceField prompting out save window???

Thanks a lot prash_bb_dev, I tried the method 2, it works great! 

 

Does anyone know how to save the choices? I may need this function later on.

Regular Contributor
Posts: 68
Registered: ‎03-17-2010
My Device: 9000,9500,8900
My Carrier: Airtel,Vodafone

Re: How to stop ObjectChoiceField prompting out save window???

 


szhuo wrote:

Thanks a lot prash_bb_dev, I tried the method 2, it works great! 

 

 


Welcome @szhuo and please mark it as solution...and give kudos also.....Man Happy


Does anyone know how to save the choices? I may need this function later on.


You can get the field's text and store the text in persistence storage.... or if you don't want persistence you may store it in a global static variable for some time..... I don't think there is any another way to do this......