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
Highlighted
New Developer
Posts: 9
Registered: ‎06-08-2009
My Device: Not Specified
Accepted Solution

How to distinguish between Save and Discard choices by user?

How in a Java app do I distinguish between user choices on "Save" or "Discard" (on screen close)? Both super.onSavePrompt() and super.onSave() return true for both choices. Any help is appreciated.
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to distinguish between Save and Discard choices by user?

[ Edited ]

Override onSavePrompt() and put up your own dialog.

 

Anyway, onSave() is never called if the user cancels the save prompt.

 

Message Edited by RexDoug on 06-08-2009 10:20 PM
New Developer
Posts: 9
Registered: ‎06-08-2009
My Device: Not Specified

Re: How to distinguish between Save and Discard choices by user?

If user cancels it's never called, but if user clicks Discard onSave() is called. I don't see any way to find out if user clicked Save or Discard, that is is the problem.
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to distinguish between Save and Discard choices by user?

[ Edited ]

So like I said, override onSavePrompt and put up your own prompt. onSavePrompt is responsible for calling onSave - so if the user cancels, you don't call it:

 

protected boolean onSavePrompt()
Invoked when the screen should prompt to save its contents.

The default implementation is empty. Overriding classes should provide a dialog and call onSave if the user has chosen to save. If the return is true, the framework will call onClose.

Returns: True if the screen should close; otherwise, false Since: JDE 3.6.0 See Also: MainScreen.onSavePrompt() Category:

 

Message Edited by RexDoug on 06-08-2009 10:42 PM
Message Edited by RexDoug on 06-08-2009 10:42 PM
New Developer
Posts: 9
Registered: ‎06-08-2009
My Device: Not Specified

Re: How to distinguish between Save and Discard choices by user?

Well, I don't think that people who designed this dialog intended for developers to overwrite it just to find out if Discard or Save was called on a built-in dialog, don't you think? There should be a way to see this. It does not make sense to include 3 buttons, 2 of which return exactly the same.
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to distinguish between Save and Discard choices by user?

[ Edited ]

"Save" calls onSave. "Cancel" does nothing, just closes the prompt. "Discard" closes the screen without calling onSave.

 

Put up your own dialog, and act according to the user response.

 

 

 

Message Edited by RexDoug on 06-08-2009 10:46 PM
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: How to distinguish between Save and Discard choices by user?

In my perspective, It is - "Save" calls save() of the Screen, save() in turn calls close() .. "Discard" calls close() directly, and "Cancel" does nothing..
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
New Developer
Posts: 9
Registered: ‎06-08-2009
My Device: Not Specified

Re: How to distinguish between Save and Discard choices by user?

Yes, the post above is correct, it resolved my problem.

 

Somehow, in my testing I saw that Save() was called on both "Discard" and "Save" actions, this got me confused. But re-testing it again produced expected results. I just did something wrong before and was not paying attention.