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
nikolay_taskov
Posts: 29
Registered: ‎03-16-2009
My Device: 8300
Accepted Solution

Problem with background application

Hello,

I have a question. How can I make an application to be always active in background after closing the MainScreen.
For example, I have an application in background. When I open it, a MainScreen is displayed. If I close this screen, the application is closed too. There is no application icon in the task manager.
I have tried to override the close() method of MainScreen:

 

 

public void close() {
UiApplication.getUiApplication().requestBackground();
}

 This works. But in this case if I change the fields from the MainScreen and click the "save" button from the prompt dialog
and after that I open the application and click ESC without making any changes, the prompt dialog is displayed again. May be it keeps the instances.

 

I have also tried to override:

 

protected void onUiEngineAttached(boolean attached) {
if(attached == false) {
MyApp.getInstance().requestBackground();
}
}

 

But there is no effect.

I would be very grateful if someone can help me.

 

Thanks in advance!!!

 

 

 

Please use plain text.
Developer
myraddin
Posts: 405
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Problem with background application

I would suggest using the second entry approach:

www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800738/800901/How_To_...

 

You can start the main app in the background, and the second entry upon icon click.

 

For more information also look at:

 

supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=10961&query.id=378012#M1...

 

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with background application

[ Edited ]

I'm not sure an alternate entry is the answer to this question - because I'm not sure what the question is.

 

It seems to me that you have correctly used requestbackground() to push your application to the background, the issue seems to be that there are Fields on the Screen that are dirty and remain so or immediately become dirty again.  As a result, when you ESC again, the Dialog comes up. 

 

If all you are concerned about is the unwanted Dialog, you might find this Thread useful: 

 

how to block the Save_Discard_Cancel Dialog

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=2808

 

If this is not the problem, please can you clarify your question a little for us.

 

Edit: Fixed typo and made post read better.

 

 

 

Message Edited by peter_strange on 04-29-2009 01:36 PM
Please use plain text.
Developer
nikolay_taskov
Posts: 29
Registered: ‎03-16-2009
My Device: 8300

Re: Problem with background application

[ Edited ]
Yes, Peter, that is the exact problem, but I use the save prompt dialog in order to save the values from
the MainScreen to the PersistenceStore. This dialog have to be shown only when there are any changes in the fields.

Thank both of you for the quick answer :smileyhappy:
Message Edited by nikolay_taskov on 04-29-2009 10:27 AM
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with background application

Is this solved or not?
Please use plain text.
Developer
nikolay_taskov
Posts: 29
Registered: ‎03-16-2009
My Device: 8300

Re: Problem with background application

No, it is not solved.

The save prompt dialog have to be shown only when the user changes the fields on the screen, but in my case it is displayed without making any changes.

Could this dialog be displayed if and only if there is any changes in the fields.

Please use plain text.
Developer
nikolay_taskov
Posts: 29
Registered: ‎03-16-2009
My Device: 8300

Re: Problem with background application

I have figured out how to check for differences of the state of the fields in the Screan with values in PersistenceStore. If my idea is working, i will report "Solved" state. 10x again
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with background application

You may be doing something in your code which is marking one or more of your Fields as dirty.  You could perhaps use a

<Screen>.setDirty(false);

at some stage when you know the Fields are OK.  I've never tried this but the documentation suggests it should work.

 

Comparing against the persisted values is a good test anyway.

Please use plain text.
Developer
nikolay_taskov
Posts: 29
Registered: ‎03-16-2009
My Device: 8300

Re: Problem with background application

I made it in that way:

 

protected boolean onSavePrompt() { String storedUserPhone = settingsManager.getSettings().getUserPhone(); String storedPassword = settingsManager.getSettings().getPassword(); String storedHost = settingsManager.getSettings().getHost(); Integer storedPort = settingsManager.getSettings().getPort(); if (!editFieldUserPhone.getText().equals(storedUserPhone) || !editFieldPassword.getText().equals(storedPassword) || !editFieldHost.getText().equals(storedHost) || !editFieldPort.getText().equals(String.valueOf(storedPort))) { int choose = SaveDialog.show(); switch (choose) { case 0: this.onSave(); break; case 1: editFieldUserPhone.setText(storedUserPhone); editFieldPassword.setText(storedPassword); editFieldHost.setText(storedHost); editFieldPort.setText(String.valueOf(storedPort)); break; default: UiApplication.getUiApplication().requestForeground(); return false; } } UiApplication.getUiApplication().requestBackground(); return false; }

 

I compare the input values from the screen fields with their corresponding values that are saved in PersistenceStore. But I had to write custom "Save_Discard_Cancel Dialog" in order to work correctly.

 

 

public class SaveDialog { public static int show() { int choose = Dialog.ask("Changes made!", new String[]{"Save", "Discard", "Cancel"}, 0); return choose; } }

 


 

 

 

Please use plain text.