-2

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

3
  • i have tried create a instance of second midlet in first and call the startapp()
    – Rana Anees
    Feb 6, 2012 at 12:12
  • creating an instance should throw SecurityException per API docs, 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 6, 2012 at 12:27
  • I am doing all for learing Purpose ya it threw an exception i have just started j2me
    – Rana Anees
    Feb 6, 2012 at 13:26

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.