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
New Developer
pascallambert
Posts: 24
Registered: ‎08-07-2008
My Device: Not Specified
Accepted Solution

MIDlet app get kick back to first screen upon call reception

I'm trying to understand why a MIDlet get kick back to the first screen when a user will accept an incoming call. I would I've expect the OS to stay on the current screen.

 

Based on the code below if you navigate up to the second screen (and even a third if there was one) and then call/answer the phone then hang up, you'll get kick to the first screen of the app.

 

Blackberry 8330 v4.3.0.124 (Platform 3.1.0.71)

 

 

package pascal; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class BBCallHandle extends MIDlet { private static BBCallHandle instance; private Display display; public BBCallHandle() { } public static void exit() { instance.notifyDestroyed(); } protected void startApp() throws MIDletStateChangeException { instance = this; display = Display.getDisplay(this); Form1.getInstance(display).go(null); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } }

 

package pascal; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; public class Form1 extends Form implements CommandListener { private Display display; private Command backCommand; private Command nextFormCommand; private Displayable previous; public Form1(String title) { super(title); } public static Form1 getInstance(Display display) { Form1 instance = new Form1("Form1"); instance.display = display; instance.initUI(); return instance; } public void go(Displayable previous) { this.previous = previous; display.setCurrent(this); } public void commandAction(Command command, Displayable item) { if (command == backCommand) doBackCommand(); else if (command == nextFormCommand) doNextFormCommand(); } private void doBackCommand() { if (previous != null) display.setCurrent(previous); BBCallHandle.exit(); } private void doNextFormCommand() { Form2.getInstance(display).go(this); } private void initUI() { append("You are in form 1"); addCommand(getBackCommand()); addCommand(getNextFormCommand()); setCommandListener(this); } private Command getBackCommand() { if (backCommand == null) backCommand = new Command("Back", Command.BACK, 0); return backCommand; } private Command getNextFormCommand() { if (nextFormCommand == null) nextFormCommand = new Command("Next", Command.SCREEN, 0); return nextFormCommand; } }

 

package pascal; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; public class Form2 extends Form implements CommandListener { private Display display; private Displayable previous; private Command backCommand; public Form2(String title) { super(title); } public static Form2 getInstance(Display display) { Form2 instance = new Form2("Form2"); instance.display = display; instance.initUI(); return instance; } public void go(Displayable previous) { this.previous = previous; display.setCurrent(this); } public void commandAction(Command command, Displayable item) { if (command == backCommand) doBackCommand(); } private void doBackCommand() { display.setCurrent(previous); } private void initUI() { append("Hello form2"); addCommand(getBackCommand()); setCommandListener(this); } private Command getBackCommand() { if (backCommand == null) backCommand = new Command("Back", Command.BACK, 0); return backCommand; } }

 

 

 

 

 

Please use plain text.
Developer
hpedroza
Posts: 22
Registered: ‎10-30-2008
My Device: Not Specified

Re: MIDlet app get kick back to first screen upon call reception

Form1.getInstance() is being called from startApp() *and* each time this happens, a new instance of Form1 will be created and set as current i.e. display.setCurrent(new Form1()). Iwould think that getting incoming call will call pauseApp() and when call ends, startApp() is called again.

 

I suggest you use System.out.println to see intances (Form1@1234abcd and Thread.currentThread()) in startApp and other "callbacks".

Please use plain text.
New Developer
pascallambert
Posts: 24
Registered: ‎08-07-2008
My Device: Not Specified

Re: MIDlet app get kick back to first screen upon call reception

Right on!

 

Thanks.

Please use plain text.