×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Maroc
    Posts
    16

    Question Launching a Midlet from another Midlet

    hi all,
    I try to lunch a midlet from anoyher, but it doesn't work

    the main midlet is:
    Code:
    package com.Rtp;
    
    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;
    import javax.microedition.lcdui.TextField;
    import javax.microedition.media.Manager;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    import com.owi.Project.Iregister;
    import com.owi.Project.Register;
    
    public class test extends MIDlet implements CommandListener {
    
    	private Form form;
    	private Display display;
    	private Command start;
    	private Command exit;
    
    	Iregister register=new Iregister();
    	
    	public test() {
    		display=Display.getDisplay(this);
    		form=new Form ("index");
    		start=new Command("start", Command.OK, 1);
    		exit=new Command("exit",Command.EXIT, 0);		
    		form.addCommand(start);
    		form.setCommandListener(this);
    	}
    
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    		
    	}
    
    	protected void pauseApp() {
    		
    
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    		
    		form.setCommandListener(this);
    		display.setCurrent(form);
    	}
    
    	public void commandAction(Command c, Displayable d) {
    		if(c==start) {
    			
    		try {
    			register.startApp();
    		} catch (MIDletStateChangeException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    			
    				
    		}else if(c==exit){
    			try {
    				destroyApp(true);
    				notifyDestroyed();
    			} catch (MIDletStateChangeException e) {
    				e.printStackTrace();
    			}			
    		}
    	}
    }
    and the other Midlet is:
    Code:
    package com.owi.Project;
    
    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;
    import javax.microedition.lcdui.TextField;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    public class Iregister extends MIDlet implements CommandListener {
    	
    	Register CRegsiter;
    	private Form form;
    	private Display display;
    	private Command Cregister;
    	private Command Cexit;
    	private TextField domaine;
    	private TextField username;
    	private TextField password;
    	private TextField port;
    
    	public Iregister() {
    		display=Display.getDisplay(this);
    		
    		form=new Form("Registration");
    		Cregister=new Command("Register", Command.OK, 1);
    		Cexit=new Command("Exit", Command.EXIT, 1);
    		domaine=new TextField("domaine", "", 20, TextField.LAYOUT_DEFAULT);
    		port=new TextField("port", "5060", 5, TextField.LAYOUT_DEFAULT);
    		username=new TextField("username", "", 20, TextField.LAYOUT_DEFAULT);
    		password=new TextField("password", "", 20, TextField.LAYOUT_DEFAULT);
    		form.addCommand(Cregister);
    		form.addCommand(Cexit);
    		form.append(domaine);
    		form.append(port);
    		form.append(username);
    		form.append(password);
    		form.setCommandListener(this);
    		display.setCurrent(form);
    
    	}
    
    	public void destroyApp(boolean arg0) throws MIDletStateChangeException {
    	}
    
    	public void pauseApp() {
    	}
    
    	public void startApp() throws MIDletStateChangeException {
    		display.setCurrent(form);
    		form.setCommandListener(this);
    
    	}
    
    	public void commandAction(Command c, Displayable d) {
    		if(c==Cexit){
    			
    				try {
    					destroyApp(true);
    					notifyDestroyed();
    				} catch (MIDletStateChangeException e) {
    					e.printStackTrace();
    				}
    				notifyDestroyed();
    					
    		}	
    			
    	}
    
    }
    what's wrong, thank for help

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: Launching a Midlet from another Midlet

    A midlet application project in J2me should have only 1 entry point as Midlet, other can be simple displayable or non-displayable classes.

    Why do you want to do this, whats the aim?

    To Launch one midlet from another on S40, try using PushRegistry with Alarm.

    On S60 with recent devices, you can do it with platform request as well.

    thanks,
    ~Amitabh

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Launching a Midlet from another Midlet

    Specifically:

    Quote Originally Posted by taoufik109 View Post
    Code:
    	Iregister register=new Iregister();
    You are not permitted to create an instance of a MIDlet - only the Application Manager is allowed to do this.

    Either, use the methods described by Amitabh above, or redesign your application so that you have only one MIDlet.

    Graham.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Location
    Maroc
    Posts
    16

    Question Re: Launching a Midlet from another Midlet

    thank for your response, please can you correct my code above (i'm new in j2me).
    the aim that I have a principal menu that allow me to call another midlet.

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Launching a Midlet from another Midlet

    Quote Originally Posted by taoufik109 View Post
    thank for your response, please can you correct my code above (i'm new in j2me).
    the aim that I have a principal menu that allow me to call another midlet.
    Why do you want to call,this another midlet from the main menu of the first midlet?

    You can simply take the single MIDlet and can set/reset the Canvas/Form from. This can fulfill the need.

    What exactly is the need?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Registered User
    Join Date
    Apr 2010
    Location
    Maroc
    Posts
    16

    Post Re: Launching a Midlet from another Midlet

    Hi,
    I Have developped several Midlet independently, and now I want to collect them in one midlet and using a menu, I can call each midlet, this is my idea.

    I don't understand what you mean by "You can simply take the single MIDlet and can set/reset the Canvas/Form from", if you have an example or document it will be better, thank.

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Launching a Midlet from another Midlet

    Quote Originally Posted by taoufik109 View Post
    Hi,
    I Have developped several Midlet independently, and now I want to collect them in one midlet and using a menu, I can call each midlet, this is my idea.

    I don't understand what you mean by "You can simply take the single MIDlet and can set/reset the Canvas/Form from", if you have an example or document it will be better, thank.
    What are you doing by the multiple midlets, I guess nothing but just will be calling the some other classes like the Canvas or forms...correct?

    You just copy all these classes in the src folder and make a menu and let user see all the menu items on the screen like canvas or form and then according to the Key/Command events just set the respective Canvas/Form as the displayable.
    I hope I am clear to you,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Registered User
    Join Date
    Apr 2010
    Location
    Maroc
    Posts
    16

    Post Re: Launching a Midlet from another Midlet

    I try to develop a softphone, so I have midlet for chat, midlet for call, midlet for sip, midlet for audio, and I don"t want to collect them in one file, so the code will be easy maintainable.

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Launching a Midlet from another Midlet

    Quote Originally Posted by taoufik109 View Post
    I try to develop a softphone, so I have midlet for chat, midlet for call, midlet for sip, midlet for audio, and I don"t want to collect them in one file, so the code will be easy maintainable.
    Ok...
    Just take these all items and make the Main Menu of these. Now do the coding in the respective classes/packages for the every items. From the midlet set the main menu class as the displayable and in this Canvas's keypressed, you can find that which item was selected by the user and then set that class as the displayable. This is so simple.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Registered User
    Join Date
    Apr 2010
    Location
    Maroc
    Posts
    16

    Post Re: Launching a Midlet from another Midlet

    thank you for your help.
    I know this is simple for an expert but for me not at all easy, because I don't know how to instanciate another midlet and make it displayable ? I try to do this with the example above but not working, can you correct the example that I poste above ? and sorry for my stupidity.

  11. #11
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Launching a Midlet from another Midlet

    Yeah I know that when someone start any technology has to face various issues. However you read the basics of the gaming first here,
    http://www.scribd.com/doc/3020560/J2...ent-with-MIDP2

    and then probably you can take lesser time for this or any kind of problems.
    http://developers.sun.com/mobility/m...icles/gameapi/
    http://www.java-tips.org/java-me-tip...e-in-j2me.html
    http://mobilegametutorials.blogspot....game-menu.html

    Please check that whether these links are of any help,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Launching an other Midlet from another using CHAPI
    By manjul_saini in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2009-08-26, 14:19
  2. launching another midlet using platformRequest()
    By prashantpersistent in forum Mobile Java General
    Replies: 1
    Last Post: 2008-06-20, 11:19
  3. j2me Midlet Verification/Validation Problem
    By Nikolaos in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2008-06-16, 16:31
  4. Pushregistry, Security Alert after signing the midlet?
    By juppi in forum Mobile Java Networking & Messaging & Security
    Replies: 15
    Last Post: 2007-08-08, 11:04
  5. Launching a MIDlet using an SMS?
    By nkn_motoko in forum Mobile Java General
    Replies: 1
    Last Post: 2001-11-06, 20:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×