| Reply | « Previous Thread | Next Thread » |
|
Hello everyone,
I'm writing a MIDlet that is a J2ME emulator of the old Casio FX7000 calculators. The J2ME emulator executes a Casio program in a separate thread. This allows the user to cancel lengthy operations and looping programs and it keeps the user-interface responsive. The interpreter that runs the program issues a Thread.yield() every time it moves to the next statement. This ensures that devices with cooperative-threading remain responsive. It all works pretty well, except for this: Only when a Casio program is busy running: For example (on my Nokia3650) when I press the Menu-button, the menu does not appear (or when holding this button: the task-manager does not appear). Only after the program ends, suddenly the phone's menu appears. But all events (keypresses/paints) that are handled by the MIDlet itself arrive in time and are handled promptly. When a Casio program is not running: Everything works fine (the interpreter-thread is waiting at the wait() statement). Is there a way around this? What do i need to call? Thread.yield() does not work. Nor wait(timeout) or sleep(timeout)... I'd like to solve this, especially for the case when a Casio program is running and the user receives a phone-call. Code:
// Simplified pseudo-code sample of the Runnable's run() method.
while (mActive)
{
synchronized(this)
{
wait(); // waiting until EXE button is pressed
// The user pressed the EXE button. Run the program.
}
Interpreter.run(program);
// done.
...
}
Interpreter.run(Program program)
{
int i = 0;
// Casio program about to be busy running.
while (i < program.mStatements.size())
{
Thread.yield();
... execute(program.mStatements.get(i));
...
i++;
}
}
Thanks! |
|
Update: When running on the emulator, these issues do not occur. Only when running on the real device.
I made some changes that allows a phone-call to come in or some other event to be handled promptly. Code:
// Simplified pseudo-code sample of the Runnable's run() method.
while (mActive)
{
synchronized(this)
{
wait(); // waiting until EXE button is pressed
// The user pressed the EXE button. Run the program.
}
Interpreter.run(program);
// done.
...
}
Interpreter.run(Program program)
{
int i = 0;
// Casio program about to be busy running.
while (i < program.mStatements.size())
{
Thread.yield();
synchronized(mSyncer)
{
if (mHalted)
mSyncer.wait();
}
... execute(program.mStatements.get(i));
...
i++;
}
}
Interpreter.halt()
{
synchronized(mSyncer)
{
mHalted = true;
}
}
Interpreter.resume()
{
synchronized(mSyncer)
{
mHalted = false;
mSyncer.notify();
}
}
This still does not allow the Menu keypress to be handled promptly, but it will halt execution until the app gets focus again. BTW: Is there a way to catch the Menu keypress on Series60 phones? |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|