How could i avoid the SAVE dialog in my custom blackberry Application? - blackberry

I am writing a blackberry application and pushing screens one after another(three in series)
Screen1 displays Screen2 and Screen2 displays Screen3
When i press "Back Key" on my Blackberry Device i.e., bold 9700, its prompts a dialog box with Question mark image and buttons "Save" "Discard" "Cancel".
Why does this dialog appears?
How can i avoid this dialog?
Please Help
Thanks
SIA

you can avoid this type of dialog by overriding onClose method for that screen :
public boolean onClose()
{
this.close();
return true;
}

There are two ways of doing this:
Override the isDirty() method of your Screen (via: Blackberry - Disable Save option in BasicEditField?):
public boolean isDirty() { return false; }
You can also override the onSavePrompt() method of your Screen (also via: Blackberry - Disable Save option in BasicEditField?):
protected boolean onSavePrompt() { return true; }

Simply Write this code in your specified class:
protected boolean onSavePrompt()
{
return true;
}
It will disable the Save Prompt Dialog Box.

Related

Handling Touch EventListener in presence of navigationClick()

In application, Whenever i move bewteen tabs a full menu, copy, switch application pop up open.
To prevent this i override navigationClick method.
Now pop is not shown. In my second tab i have implemented drop down list. Because i have override navigationClick method when i click on drop down list it is not showing me list of items.
Any idea will be apperciated.
Update:
Here is navigationClick implementation:
public boolean navigationClick(int status, int time) {
return true;
}
Make sure while selecting a tab, no errors occur which probably could be the reason for the menu options to pop up. if this is fixed i guess the subsequent problem will be dissolved!
Out of my experience i have observed the menu pops up in blackberry when a NullPointerException event occurs.
Just check the logs or debug to make sure no exception occurs when you navigate between tabs
If you want to click the labelfield then:
LabelField labelField=new LabelField("Click")
{
protected boolean navigationClick(int status, int time)
{
doLabelFieldClicked();
return true;
}
}
and if Menu option is highlighted then override this:
public boolean onMenu(int instance)
{
return true; //It doesn't show the Menu option.
}
If I am thinking wrong let me know.
I solved this problem by implementing navigationClick() while creating lablelField
tab5 = new LabelField("News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
{
public boolean navigationClick(int status, int time)
{
return true;
}
};

How to push new screen from global screen in blackberry?

Here I am display push notification in globalscreen in blackberry, I need to push screen by clicking OK button of the dialog. I want to start app by clicking the ok button.
Please help me.
Thanks in advance!
I'm not 100% sure I understand what you want, but if this doesn't work, just add a comment and I'll try to give you a better answer.
First, read this on pushing global screens
and this on performing actions after receiving global alerts
Your code, if I'm understanding correctly, should be similar to the second link's example.
Then, if you implement the DialogClosedListener, like in the second link, you might have something like this:
called from the background when you get notified:
Dialog myDialog = new Dialog(Dialog.D_OK_CANCEL, "Hello", Dialog.OK, null, 0);
myDialog.setDialogClosedListener(new MyListener());
UiApplication.getUiApplication().pushGlobalScreen(myDialog, 1, true);
implementation of your dialog listener:
private class MyListener implements DialogClosedListener {
public void dialogClosed(Dialog dialog, int choice) {
switch (choice) {
case Dialog.OK:
// ok clicked
UiApplication.getUiApplication().requestForeground();
break;
case Dialog.CANCEL:
// cancel clicked. or escape pressed
break;
default:
break;
}
}
}
And, then in your UiApplication class, you can respond to activation, which will happen if the user selects Ok from the Dialog:
public class MyApp extends UiApplication {
private boolean _nextScreenShowing = false;
public void activate() {
super.activate();
if (!_nextScreenShowing) {
pushScreen(new NextScreen());
_nextScreenShowing = true;
}
}
}
I show the _nextScreenShowing variable, just to make sure you think about whether pushing the next screen is appropriate. It probably won't be every time activate is called. You may need to keep track of that boolean flag by responding to the Application.deactivate() method, or maybe Screen.onExposed() or Screen.onObscured(). All that depends on how your app works.

Hiding all default menu items in blackberry

I had to remove all the default menus in blackberry. I have used the following code
protected void makeMenu(Menu menu, int instance) {
// if you want default menu items, uncomment bellow line
// super.makeMenu(menu, instance);
}
But after this, still it was showing the default menu like "Switch Application", for that i have used super(NO_SYSTEM_MENU_ITEMS) in the screen class constructor.
Now all menus are removed, but it is still showing "empty menu" as shown in the image below.
Please let me know how could we remove all menu items and make it empty?
try this in your main screen
public boolean onMenu(int instance) {
// TODO Auto-generated method stub
return false;
}
You can also do that.
public boolean onMenu(int instance) {
return super.onMenu(2);
}
Because for creating menu instance value is 0. So, for any non zero value it doesn't create the menu.

Blackberry popup menu appear on Button click event

I have a problem that popup menu appear when I click a button field. I will solve it by using Buttonfield.consumeclick but it also appears on RichTextField focus. How can I solve this? I am overriding RichTextField method, and that is the reason the popup menu appears.
ButtonField c = new ButtonField("button", FIELD_LEFT | ButtonField.CONSUME_CLICK) {
protected boolean navigationClick(int status, int time) {
Status.show("Button has clicked");
// write your code.
return true;
}
}

hiding menu on click

I am using NullField() in one of my screen so that the default focus should not be on any of the button . but when i am clicking on the screen where no field is there , menu screen is being displayed. i dont want that menu screen to be poped up tough it should open when i click menu button.
Thanks alot
override method.
protected boolean navigationClick(int status, int time) {
Field focus = UiApplication.getUiApplication().getActiveScreen()
.getLeafFieldWithFocus();
if (focus instanceof NullField) {
return true;
}
return super.navigationClick(status, time);
}
Note:This code is only for giving you hint.

Resources