-2

I want to know how to switch between two Midlets i.e. Go from First Midlet to Second Midlet on pressing command?

gnat
  • 6,213
  • 108
  • 53
  • 73
Rana Anees
  • 307
  • 2
  • 13
  • i have tried create a instance of second midlet in first and call the startapp() – Rana Anees Feb 06 '12 at 12:12
  • _creating an instance_ should throw SecurityException [per API docs](http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/midlet/MIDlet.html#MIDlet()), didn't you know that? Also the way you describe it I wonder why do you think you need second midlet at all? Is there anything you can't do by using plain java object/thread? – gnat Feb 06 '12 at 12:27
  • I am doing all for learing Purpose ya it threw an exception i have just started j2me – Rana Anees Feb 06 '12 at 13:26

1 Answers1

0

MIDP 1.0 specified only one way to start a MIDlet: manual activation by the user.The MIDP 2.0 specification adds two new mechanisms to launch a MIDlet: in response to an incoming connection or at a scheduled time. The new javax.microedition.io.PushRegistry class handles both.
You can use Alarms to Launch MIDlets.The PushRegistry.registerAlarm() method Registers a timer-based alarm to launch the Midlet.It supports one outstanding wake up time per MIDlet in the current suite.(So target midlet must be registered in the JAD or manifest file)

In the MIDlet source code include:

...

import  javax.microedtion.io.PushRegistry;   

and in your commandAction method:

...
String  MIDletname = "yourMIDletName";
Date date = new Date();
long currentTime = date.getTime();
long nextTime = currentTime  + 2000;
PushRegistry.registerAlarm( MIDletname, nextTime );
...

References:
How can a MIDlet be launched automatically?
The MIDP 2.0 Push Registry

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167