×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: How do I quit?

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    34

    How do I quit?

    I've managed to get most of this game working, but I can't quit.

    It's being called from a midlet like this:

    /////////////////////////////////////////////////////////////////////

    public class J2MEVexedMidlet extends MIDlet {

    private Display display;

    public void startApp() {
    display = Display.getDisplay(this);
    J2MEVexed gameCanvas = new J2MEVexed();
    gameCanvas.start();
    display.setCurrent(gameCanvas);
    }

    public Display getDisplay() { return display; }

    public void pauseApp() { }

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

    public void exit() {
    System.gc();
    destroyApp(false);
    notifyDestroyed();
    }
    }

    /////////////////////////////////////////////////////////////////////


    and a seperate .java file holds J2MEVexed, with the following methods (amongst others)

    public void start() {
    isPlay = true;
    myThread = new Thread(this);
    myThread.start();
    }

    public void stop() { isPlay = false; }

    // most of the main loop code here...
    // then:

    try {
    Thread.sleep(delay);
    } catch (InterruptedException ie) {}



    How do I get the midlet to quit nicely?

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: How do I quit?

    Seems like you have an infinite loop in you midlet. destroyApp() calls exit(), which calls in turn destroyApp()...

    You have to also have a command in the UI which then calls the method for exiting the midlet.

    Hartyti

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    8

    Re: How do I quit?

    Public void destroyApp(boolean unconditional) if (YourGameCanvas!=null)
    YourGameCanvas.Stop();
    system.Gc();notifydestroyed(); ,,,then in your exit command call exit(),,, protected void exit()
    destroyApp(true);
    Last edited by cristoforo; 2006-05-25 at 10:11.

  4. #4
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: How do I quit?

    Hi
    As hartii said please avoid looping the exit().

    Thanks
    Soku

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    34

    Re: How do I quit?

    Thanks.
    But I can't see any of the methods in J2MEVexedMidlet from J2MEVexed. Do I have to make one of the methods static, or pass something into J2MEVexed?

  6. #6
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: How do I quit?

    Hi poldie,
    Remove the exit() from the destroyApp() and then just synchronize the method exit()(not mandatory).also call the exit command from the commandAction by creating a command.

    Thanks
    Soku

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    34

    Re: How do I quit?

    Quote Originally Posted by soku123
    Hi poldie,
    Remove the exit() from the destroyApp() and then just synchronize the method exit()(not mandatory).also call the exit command from the commandAction by creating a command.

    Thanks
    Soku
    I have no commands or commandActions or anything, and I don't want any. (I'm handling the UI completely myself.) Or are you saying I *have* to call exit in that way and there's no other way to do it? exit isn't visible to my class - do I just have to make it visible somehow?

    I've read a little about synchronize - I thought that was to do with preventing multiple threads from entering the same method at the same time?

  8. #8
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: How do I quit?

    Hi Poldie,
    i suppose what i suggested is the standard way of doing.can u tel me how you are handling it yourself.

    Thanks
    Soku

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    34

    Re: How do I quit?

    Quote Originally Posted by soku123
    Hi Poldie,
    i suppose what i suggested is the standard way of doing.can u tel me how you are handling it yourself.

    I'm reading the keys with:


    int keyStates = getKeyStates();

    if ((keyStates & GAME_C_PRESSED) != 0)
    bRestartLevel = true;


    In my 'run' method I restart the level if required, move on to the next level if the current level has been completed. Soon I'll have a key which ends the current game and takes you to a title screen, allowing you to select levels, options etc. No command listeners or anything - I'm doing it myself. I have a full screen game and all the space is accounted for - I don't want the typical ugly `white box with some black text in it` effect you see in a lot of apps/games on phones!

    Surely there's just a method I can call that says `ok, I'm done - quit this app completely`?

  10. #10
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: How do I quit?

    Hi poldie,

    You can call "exit()" method where the user decides to quit from the game. but don't put it in the destroyApp().

    the destroyApp is called only when u call the exit method. right??


    Wang

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    34

    Re: How do I quit?

    Quote Originally Posted by wang_shui
    Hi poldie,

    You can call "exit()" method where the user decides to quit from the game. but don't put it in the destroyApp().

    the destroyApp is called only when u call the exit method. right??

    Wang
    destroyApp is part of the Midlet interface. I didn't think I could call that myself. Calling exit() makes sense only it's not in scope from my code, so I can't. I'm probably missing something really obvious here!

  12. #12
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    170

    Re: How do I quit?

    Hi Poldie my destroyedApp function looks like this and it works fine. :
    protected void destroyedApp(boolean arg0)
    {
    notifyDestroyed();
    }

    It is called with destroyedApp(false);

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    34

    Re: How do I quit?

    Quote Originally Posted by lpinguin
    Hi Poldie my destroyedApp function looks like this and it works fine. :
    protected void destroyedApp(boolean arg0)
    {
    notifyDestroyed();
    }

    It is called with destroyedApp(false);
    I have a similar method - destroyApp - which is a method of Midlet, which I'm subclassing in my J2MEVexedMidlet class.

    But my J2MEVexedMidlet class creates a J2MEVexed object, and it is from within J2MEVexed that i'm trying to quit, and it can't see exit or destroyApp. I just get compile errors. And if I put:

    J2MEVexedMidlet.destroyApp();
    J2MEVexedMidlet.exit();

    I get 'can't find symbol' for the first line, and 'non-static method exit() cannot be referenced from a static context'. Note: the word static does not appear once anywhere in my source code!

  14. #14
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: How do I quit?

    Hi Poldie,

    You can call the destroyApp(); directly from another class.
    You have to make an object of the midlet class in the class u r trying to call the destroyApp or exit().

    or else u change exit() method to "public static void exit() "

    http://forum.java.sun.com/thread.jsp...sageID=1043471

    Wang

  15. #15
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: How do I quit?

    Hi Poldie,

    First of all, i think Hartti is right and you should fix your code and avoid the "indirect" recursion when considering the destroyApp() method calls.

    AFAIK you should avoid calling destroyApp() directly. It's a lifecycle method and will be called by the AMS / JAM. Your interface for notifying the intention to terminate is the notifyDestroyed() method of MIDlet class.

    I don't know which device is yours but on Symbian phones we have the following:

    "destroyApp will typically be called by the AMS when the operating system notifies the AMS of low memory conditions or power down (switch off). destroyApp may also be called by the AMS in response to user action to kill a running application (for instance on Series 60 using the “Menu” key to bring up running applications, then the “Clear” key to terminate the selected application)."

    "Now let us look in more detail at how these methods are employed. If the MIDlet wants to terminate itself (as opposed to being moved to the DESTROYED state by the AMS via a call to destroyApp) it should perform all necessary clean-up and then call notifyDestroyed. On receiving a notifyDestroyed notification the AMS state machine will assume the MIDlet is ready to be terminated and change the state of the MIDlet to DESTROYED. The AMS will not call destroyApp after a notifyDestroyed notification."
    Many standard texts (and indeed IDE templates) incorrectly give example code such as:

    if (c == exitCommand) {
    destroyApp();
    notifyDestroyed();
    }
    ...

    "The rationale for the above is that typically the clean-up that needs to be performed prior to calling notifyDestroyed is identical to the clean-up performed in the implementation of the destroyApp method. However, a strict interpretation of the MIDP specification would predicate against this style. destroyApp is a call-back method that is invoked by the AMS to indicate to the MIDlet that it is going to be destroyed by the AMS. Just as one would not call actionPerformed in AWT directly, or commandAction in MIDP directly, the MIDlet should not directly call destroyApp. A more correct and robust style is shown below."

    This is from this doc:

    Programming the MIDP Lifecycle on Symbian OS
    http://www.symbian.com/developer/tec...plifecycle.pdf

    Check pages 3 and 4. Hope it helps!

    BR,

    Juarez Junior

Similar Threads

  1. How to quit L2CAPConnectionNotifier.acceptAndOpen ?
    By akokchai in forum Mobile Java General
    Replies: 0
    Last Post: 2004-10-06, 05:44
  2. Application quit in the middle of execution
    By siukay823 in forum Symbian
    Replies: 15
    Last Post: 2004-05-11, 10:10
  3. Replies: 0
    Last Post: 2004-04-08, 15:20
  4. Replies: 1
    Last Post: 2004-01-22, 11:32
  5. SOS! EXEC3 error when quit application using Nokia 7650 Exit Button
    By rochellesun in forum Mobile Java General
    Replies: 0
    Last Post: 2003-02-27, 00:37

Posting Permissions

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