Physical back button always quits cn1 app on Nokia Asha devices

156 views
Skip to first unread message

Jo nas

unread,
Nov 24, 2013, 1:37:41 PM11/24/13
to codenameone...@googlegroups.com
Hello,
my app is not approved in the ovi store, because the physical back button always quits the app on asha devices, even on the second or third form. I have set a back button in these forms. I think this is a bug. Can you maybe suggest a workaround? Thank you!

Greetings,
Jonas 

Shai Almog

unread,
Nov 24, 2013, 2:19:13 PM11/24/13
to codenameone...@googlegroups.com
Hi,
I think the reason is that you don't have a soft back button that they can navigate with so they fail because there is no way to go back.
Asha devices expect you to provide a softbutton area where you can press back. Did you change command behavior?

Jo nas

unread,
Nov 24, 2013, 2:24:46 PM11/24/13
to codenameone...@googlegroups.com
yeah i put the behaviour to native.. is that wrong?

Shai Almog

unread,
Nov 24, 2013, 2:40:02 PM11/24/13
to codenameone...@googlegroups.com
Yes. You should leave it as the default (remove the entry).

Jo nas

unread,
Nov 24, 2013, 3:06:00 PM11/24/13
to codenameone...@googlegroups.com
I did that and it still doesn't work :(

Shai Almog

unread,
Nov 25, 2013, 1:28:42 AM11/25/13
to codenameone...@googlegroups.com
It seems that as usual Nokia f'ed up on the bloody device and API.
In the next server update I'll add a feature that will allow you to change the jad for Nokia devices where you can define forceBackCommand=true
This will add a special command that will effectively perform what they want here: http://developer.nokia.com/Community/Wiki/Java_ME_Command_mapping_for_Nokia_Asha
Notice that this isn't a build argument, you need to edit the resulting jad and add it there.

Matthias Bay

unread,
Jan 17, 2014, 12:44:24 PM1/17/14
to codenameone...@googlegroups.com
Hi,

I've got the same problem (especially Asha 501). When pressing the hardware-back-button the native closing-dialog appears.
I've added "forceBackCommand: true" to the jad-file and now nothing happens when pressing the button in the first form, in the second form the native closing-dialog appears.
On the Simulator (with the Asha 501 Skin) the Command that has been set with setBackCommand() is called.
Can you help me?

Thanks in advance, Matthias Bay

Shai Almog

unread,
Jan 17, 2014, 1:51:58 PM1/17/14
to codenameone...@googlegroups.com
Hi,
did you define a back command?
I think you always need to define one for this to work as expected.

Matthias Bay

unread,
Jan 17, 2014, 3:40:03 PM1/17/14
to codenameone...@googlegroups.com
I did something like
        setBackCommand(new Command("") {
           
@Override
           
public void actionPerformed(ActionEvent evt) {
                doStuff
();
           
}
       
});
which works perfect on the simulator.
I did not use setCommandBehaviour().
Also, if I override keyPressed(int keyCode) in the Form, on the simulator pressing the button invokes keyPressed with keyCode 27, on the real device keyPressed is not invoked.

Shai Almog

unread,
Jan 18, 2014, 2:42:08 AM1/18/14
to codenameone...@googlegroups.com
Back and softkeys are platform specific, you will not get consistent keycodes since we don't get them.
Are you showing native forms or something like that?
I don't see a reason this will behave differently between the various forms?

Matthias Bay

unread,
Jan 18, 2014, 9:14:03 AM1/18/14
to codenameone...@googlegroups.com
No, I'm not using native Forms.
Maybe there is a difference because I've overridden keyPressed() in the second form?
Today I wanted to test if it works if I change commandBehaviour to native: it does not without "forceBackCommand: true" and with "forceBackCommand: true" I get a NullPointerException during the installation.
Is it possible to use native J2ME Code for this problem? Then I could do something like shown here: http://developer.nokia.com/Community/Wiki/Java_ME_Command_mapping_for_Nokia_Asha, but I would need the native Canvas

Shai Almog

unread,
Jan 18, 2014, 12:25:49 PM1/18/14
to codenameone...@googlegroups.com
You can use native interfaces http://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html
However, you don't need to since we add the back command ourselves when you activate that flag.
Since the UI always shows one canvas this won't be a problem

Matthias Bay

unread,
Jan 20, 2014, 10:45:08 AM1/20/14
to codenameone...@googlegroups.com
The problem is that I get a IllegalArgumentException: null when adding "forceBackCommand: true" to the jad file.

How can I get the native canvas? In CN1 I only know a method for displaying a native Canvas and in J2ME I can get the Display for a MIDlet (Display.getDisplay(MIDlet m) ) and the Displayable (which is the Canvas) of this Display (display.getCurrent() ), so I would need the MIDlet Object.

Shai Almog

unread,
Jan 20, 2014, 1:08:22 PM1/20/14
to codenameone...@googlegroups.com
The MIDlet instance is passed to your main classes init(Object) method as the object. Just store it in a public static variable then you can access that variable from your "native" code.
You can check out the source code for the MIDP port in SVN and look at the GameCanvasImplementation class, you can see there that we clearly create the back command as Nokia recommends when that flag is set.

Matthias Bay

unread,
Jan 22, 2014, 3:30:34 PM1/22/14
to codenameone...@googlegroups.com
Ah, the IllegalArgumentException was caused because I user Windows Editor, which messed up the format (newLine...) of the jad-file.
Now I edit it with NetBeans, which works fine; I can install the app without errors.
But still the Back-Key does not work.

Is it possible that the phone only looks for the property in the MANIFEST (which I didn't edit)? Since the .jad file is not necessarry on asha, jad and jar are both shown in the filemanager, the app can be installed without the jad...
If this could be the problem, how can I change the property in the MANIFEST? Or can I change it in the app (e.g. in the init() method)?

Shai Almog

unread,
Jan 23, 2014, 12:47:00 AM1/23/14
to codenameone...@googlegroups.com
According to the spec no. You also mentioned the app does behave differently after you set the value in the jad file right?

Matthias Bay

unread,
Jan 24, 2014, 4:57:14 PM1/24/14
to codenameone...@googlegroups.com
With the correct .jad file nothing happens, so I thought it was not working correct, but in fact, it did, because the asha-"close app" dialog was no more shown.

Then I tried using COMMAND_BEHAVIOR_NATIVE again, and the correct command was invoked (also keyPressed was invoked with keyCode -11).

Also I think some Errors (".jar is corrupt") occured because I edited the jad file and re-copied only the jad file to the device.
Asha didn't like the files any more (maybe because of the different time?).
But thats not important, I can now use the Command set with setBackCommand on Asha correctly.

Thanks for your help!

Shai Almog

unread,
Jan 25, 2014, 3:14:24 AM1/25/14
to codenameone...@googlegroups.com
Great to hear.
Every time you build we generate a new jad so with every new build you will need to make that change to the jad. Modification date isn't important but the jad does include some things including the specific size of the jar which must be correct.
Reply all
Reply to author
Forward
0 new messages