×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    93

    Thumbs up How to call destroyApp() method outside the midlet class.

    How to call destroyApp() method outside the midlet class.

    Actually i am using a main midlet(with startApp, pauseApp,destroyApp). And another class for some operations. In this class, i want to call the Application to destroy. How to call destroyApp method.


    by

    Ram

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

    Re: How to call destroyApp() method outside the midlet class.

    Quote Originally Posted by ramtrg View Post
    How to call destroyApp() method outside the midlet class.

    Actually i am using a main midlet(with startApp, pauseApp,destroyApp). And another class for some operations. In this class, i want to call the Application to destroy. How to call destroyApp method.


    by

    Ram
    In the class you are referring to, must have the MIDlet object in itself, and hence you can call the method.

    To get this done you should pass the MIDlet's reference in the constructor while you are initializing the class, using that you can call the method,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: How to call destroyApp() method outside the midlet class.

    Quote Originally Posted by ramtrg View Post
    How to call destroyApp() method outside the midlet class.

    Actually i am using a main midlet(with startApp, pauseApp,destroyApp). And another class for some operations. In this class, i want to call the Application to destroy. How to call destroyApp method.


    by

    Ram
    You can make A Static constructor which you Can Call it From EveryWhere You Can Made That:
    Code:
    // put that in the Constructor of The MiDlet:
    
            public static MIDlet instance;
    
    //and in your midlet class put this
    
            instance=this;
    
    // Create a Static void like destroyApp()
    
           public Static void quitApp(){
           instance.destroyApp(true);
           instance.notifyDestroyed();
           instance=null;
           System.gc();
    }
    Then u Can Call it From Any Where This Way:
    (Your MiDlet Class).quitApp();

    try it and inform me if it doesn't work

    BUFFON
    Let The Impossible Happen!!!

  4. #4
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    93

    Re: How to call destroyApp() method outside the midlet class.

    Thank You very much...buffon... I tried as per your guide... It is working very good....


    Also Thank you raj sir..

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    3

    Re: How to call destroyApp() method outside the midlet class.

    Quote Originally Posted by ramtrg View Post
    How to call destroyApp() method outside the midlet class.

    Actually i am using a main midlet(with startApp, pauseApp,destroyApp). And another class for some operations. In this class, i want to call the Application to destroy. How to call destroyApp method.


    by

    Ram
    cause destroyApp is a protected method you can not access it outside from the midlet package.. in your case you can not access it directly from other class.
    so just create a new method in the midlet class and call destroyApp method from this new method and if you make it static you dont have to make a midlet class object to call this method from different class
    here is the example:


    public class midletsub extends MIDlet implements CommandListener {

    //declare a new class type
    public static midletsub instance;

    //here is the constructor of the the class
    public midletsub() {
    instance = this;
    }

    //here is your new method

    public static void quitApp(){
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance=null;
    System.gc();
    }

    }

    }




    now put this in any another class to destroy the application

    midletsub.quitApp();

  6. #6
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Re: How to call destroyApp() method outside the midlet class.

    Hi,

    i have been try the source code above but there some error in my code... here's the code :


    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;


    public class gameMidlet extends MIDlet implements CommandListener{
    public gameCanvas canvas;
    public Display display;
    public static MIDlet instance;

    public gameMidlet() {
    canvas = new gameCanvas();
    instance = this;
    }

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }

    protected void pauseApp() {
    // TODO Auto-generated method stub
    }

    protected void startApp() throws MIDletStateChangeException {
    display = Display.getDisplay(this);
    canvas.start();
    display.setCurrent(canvas);
    }

    public static void quitApp(){
    instance.destroyApp(true); -----> error
    instance.notifyDestroyed();
    instance=null;
    System.gc();
    }

    public void commandAction(Command arg0, Displayable arg1) {
    // TODO Auto-generated method stub
    }

    }

    and i call the method :

    gameMidlet.quitApp();

    but, theres some error on method quitApp() on instance.destroyApp(true);
    erorr message = "the method destroyApp(boolean) from the type midlet is not visible"

    can somebody help me pls? thx b4...really need help ASAP~

    regards,

    robz

  7. #7
    Nokia Developer Moderator
    Join Date
    Dec 2011
    Posts
    174

    Re: How to call destroyApp() method outside the midlet class.

    Hi robz218,

    If the MIDlet is closed by the platform the MIDlets destroyApp() method is called with the argument true and the MIDlet will be destroyed. You don't have to call notifyDestroyed() method after that.

    If you want close the MIDlet yourself by pressing the exit button, then call the notifydestroyed() method. When notifyDestroyed is called it notifies the AMS(Aplication Management Software) that the midlet has entered Destroyed state and all the resources held my the MIDlet are reclaimed.

    Below is a link to implementing MIDlet lifecycle requirements and more about destroyApp() and notyfyDestroyed().
    http://library.developer.nokia.com/i...BA1B1ABC3.html

    For example...
    Code:
    public class gameMidlet extends MIDlet implements CommandListener{
    	public gameCanvas canvas;
    	public Display display; 
    	public static MIDlet instance;
    
    	public gameMidlet() {
    		canvas = new gameCanvas();
    		instance = this;
    	}
    
    	public void destroyApp(boolean unconditional) {
    		//notifyDestroyed();
    	}
    
    	protected void pauseApp() {
    		// TODO Auto-generated method stub
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    		display = Display.getDisplay(this);
    		canvas.start();
    		display.setCurrent(canvas);
    	}
    
    	/*
    	public void quitApp(){
    		instance.destroyApp(true); -----> error
                                    instance.notifyDestroyed();
                                    instance=null;
                                    System.gc();
    	}*/
    
    	public void commandAction(Command arg0, Displayable arg1) {
    		// TODO Auto-generated method stub 
    	}
    
    }
    And then from your gameCanvas class call
    Code:
    public void exit()
    {
             gameMidlet.instance.notifyDestroyed();
    }
    -tiviinik

  8. #8
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Re: How to call destroyApp() method outside the midlet class.

    wow thx tiviinik.. that works very well

    btw can i asked about insert audio into j2me too..? i have tried many script from many source but nothing work good... can u help me?

    thanks before~

  9. #9
    Nokia Developer Moderator
    Join Date
    Dec 2011
    Posts
    174

    Re: How to call destroyApp() method outside the midlet class.

    Hi Robz218,

    Below a link how to play sound in Jave ME.

    http://www.developer.nokia.com/Commu...und_in_Java_ME

    -tiviinik

Similar Threads

  1. A couple of questions regarding exiting midlets and the destroyApp method
    By dumbledore1905 in forum Mobile Java General
    Replies: 2
    Last Post: 2010-11-23, 21:44
  2. Doubt in destroyApp() method?
    By jayesh_nokia in forum Mobile Java General
    Replies: 2
    Last Post: 2010-08-09, 20:35
  3. Replies: 2
    Last Post: 2006-08-30, 21:33
  4. When to call virtual method in base class
    By rossj1 in forum Symbian
    Replies: 1
    Last Post: 2004-03-16, 08:42
  5. problem not invoke destroyApp method in 3650 phone...
    By crony94 in forum Mobile Java General
    Replies: 3
    Last Post: 2003-06-12, 06:41

Posting Permissions

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