ID | KIJ001579 | Creation date | April 23, 2010 |
Platform | S60 5th Edition | Devices | Nokia N97, Nokia N97 mini |
Category | Java ME | Subcategory | Location API (JSR-179) |
Keywords (APIs, classes, methods, functions): Orientation.getOrientation() |
Description
Orientation.getOrientation() returns the terminal's current orientation. This information can be retrieved from Nokia devices equipped with built-in magnetometer hardware.
On S60 5th Edition devices, heavy usage of Orientation.getOrientation() results in the location MIDlet closing either without an exception or with java.lang.OutOfMemoryError. The closing happens right after the 110th method call.
How to reproduce
1. Implement a test MIDlet by using the following code:
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.location.LocationException;
import javax.microedition.location.Orientation;
import javax.microedition.midlet.*;
public class LocationTest extends MIDlet {
Display d;
Form f;
boolean running = false;
Thread t = null;
protected int interval = 1000;
public LocationTest() {
d=Display.getDisplay(this);
f=new Form("Location Test");
startRequesting();
}
public void startApp() {
d.setCurrent(f);
}
public void show(String s) {
f.append(s);
}
//Implement the orientation updating activity within a thread
public void startRequesting() {
t = new Thread(new Runnable() {
public void run() {
running = true;
try {
while (running) {
updateOrientation();
Thread.sleep(interval);
}
} catch (InterruptedException ex) {
show("Exception: "+ex.toString());
}
}
});
t.start();
}
int num = 0;
private void updateOrientation() {
Orientation o;
String s;
try {
f.deleteAll();
o = Orientation.getOrientation();
show("Orientation.getOrientation(): "+num);
num++;
}
catch (LocationException ex) {
show("Exception: " +ex.toString());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
2. Install the MIDlet and wait for it to reach the 110th method call of Orientation.getOrientation().
Solution
This issue is expected to be fixed in future firmware releases for the affected devices