×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    5

    How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    The phone I used is Nokia N73.
    I tried to write the stop functions in both pauseApp and hideNofify .
    But none of the stop function works.
    Via my test, seems both pauseApp and hideNofify were not been called.
    (The pauseApp works good on WTK simulator)

    Does any body know why the pauseApp and hideNofify don't work?
    Is there any way to make it work? Is there any other workaround to solve this problem?

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

    Thumbs up Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Hi lixinso,
    In order to pause the game you have to make sure that
    1.When there is any of the interrupt,occurs,the control is going to hideNotify() and
    2.When the incoming intrrupt ends,and the 1 step was successfully handled,the contro, went back to the showNotify().

    As the name of the methods suggest,when the canvas is visible the control is supposed to be inside the showNotify() else in the hideNotify().Please read the more information on the web.

    Now in order to successful implementation of handling the incoming intrrupt you have to do the following,
    1.As soon as the intrrupt comes,you have to store the currentState of the game.and stop the all sounds.and you can draw any custom message for the user to explplain that the game is interrupted.You have to control the thread.
    2.If intrrupt is over than just again reset the copied/stored state of the game state .and then continue with the game.One more thing if game is based on the time(I mean like after 10 minute the game will be over) than you have to store the time when the intrrupt comes.

    Are these lines helpful for you,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    5

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Hi raj_J2ME , Thank you very much for you reply.

    The current situation is:
    I have the stop function in the game to stop game, I want to call the stop function when Incoming Call, so I wrote the the stop function in pauseApp(), and hideNofify(). I expect that when Incoming call comes, the pauseApp() or hideNofify() function can be called automaticly. The the pauseApp() or hideNofify() will call my stop game function.

    So the point is both pauseApp() and hideNofify() haven't been called, that made me headache.

    I run the same app on WTK2.5.2 and Motorola V3, the pauseApp() was called by system automaticly. Is Nokia N73 much special than other phones to handle Incoming Calls?

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    pauseApp() is generally unreliable.

    hideNotify() should be called, to my knowledge, on all Nokia devices, for he currently displayed Canvas. Are you quite sure than hideNotify() is not called? Do you have a Canvas displayed?

    Be careful about putting code in both methods, as some devices will call both, and you may end up in a "double-pause" state.

    Graham.

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Quote Originally Posted by lixinso View Post
    Hi raj_J2ME , Thank you very much for you reply.

    So the point is both pauseApp() and hideNofify() haven't been called, that made me headache.
    Hi,
    are you sure that the hideNotify() was not called.Have you checked the same by putting the println() statement inside.you should put the println() statement in the same and then, put the intrrupt,like incoming call.

    are you using the canvas/gamecanvas?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Smile Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Quote Originally Posted by grahamhughes View Post
    pauseApp() is generally unreliable.

    Be careful about putting code in both methods, as some devices will call both, and you may end up in a "double-pause" state.

    Graham.
    Hi Grahm,
    do you have a real life experience about the quoted line,kindly share.I am surprise that the both methods can be called at the same time.Since the canvas's isVisible() can be either true or false,
    am I correct?
    please explain.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Event methods should not happen at the same time, since they come from a queue (some devices may allow this to happen, but very few).

    If the application goes into the background, some devices will call pauseApp(). If there is a Canvas on the screen, then the device may call hideNotify(). If it calls both, then it might call them in either order. So, hideNotify() might get called, with pauseApp() immediately after.

    For this reason, it is important to make sure that the code for putting the game into a "paused" state does not break if the game is already paused.

    Many Nokia devices never call pauseApp(). So far as I know, all Nokias call hideNotify().

    Also,I recommend against trying to stop and re-start Threads when the game pauses. This can have unexpected side-effects on some devices.

    Graham.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    5

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Hi Dear raj_J2ME and grahamhughes ,
    Thanks for you replay.

    I just wrote a small program to test the Incoming Call.

    I tried to use a counter to count the Interuptions, when either pauseApp or hideNofify called.

    When the app runs on N73, the counter that draws on canvas didn't added up
    So I think the pauseApp,hideNofify was not called.

    Here is the source code:

    An MIDlet and a Canvas.
    =====================
    canvas1.java
    ------------
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;

    public class canvas1 extends Canvas {
    long t1 = 0;
    long d1 = 0;
    Graphics g1;
    boolean show = true;
    public canvas1() {
    }

    protected void paint(Graphics arg0) {
    arg0.setColor(255, 255, 255);
    arg0.fillRect(0, 0, this.getWidth(), this.getHeight());
    arg0.setColor(0, 0, 0);
    arg0.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
    arg0.drawString(String.valueOf(key.count), key.count * 10, 0, Graphics.LEFT| Graphics.TOP);
    g1 = arg0;
    }

    public void showNofify() {
    key.count += 1;
    this.repaint();
    System.out.println(key.count);
    }

    public void hideNofify() {
    key.count += 1;
    this.repaint();
    System.out.println(key.count);
    }
    }

    ==================
    key.java
    --------------
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;

    public class key extends MIDlet {
    public static MIDlet mid1;
    public static int count = 0;
    canvas1 c1 ;
    public key() {
    c1= new canvas1();
    Display d1 = Display.getDisplay(this);
    d1.setCurrent(c1);
    mid1 = this;
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

    }

    protected void pauseApp() {
    count +=1;
    c1.repaint();
    }

    protected void startApp() throws MIDletStateChangeException {
    count +=1;
    c1.repaint();
    System.out.println(key.count);
    }
    }

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Hi,
    So far as I know, all Nokias call hideNotify().
    Me too,agree with you,
    Also,I recommend against trying to stop and re-start Threads when the game pauses. This can have unexpected side-effects on some devices.
    Again thats truth,

    Thanks man,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Here's the test app I use...

    PHP Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.*;

    public class 
    Interrupt extends MIDlet implements CommandListener {

        private 
    TestCanvas tc;
        private 
    boolean firstStarttrue;

        public 
    Interrupt() {
            
    tc = new TestCanvas();
            
    tc.addCommand(new Command("Exit"Command.EXIT, 1));
            
    tc.setCommandListener(this);
        }

        public 
    void startApp() {
            
    tc.addEvent("sa");
            if (
    firstStart) {
                
    firstStart false;
                
    Display.getDisplay(this).setCurrent(tc);
            }
        }

        public 
    void pauseApp() {
            
    tc.addEvent("pa");
        }

        public 
    void destroyApp(boolean uncond) {
            
    // do nothing
        
    }

        public 
    void commandAction(Command cDisplayable d) {
            if (
    c.getCommandType() == Command.EXIT) {
                
    notifyDestroyed();
            }
        }

        private static class 
    TestCanvas extends Canvas {
            private 
    Vector events = new Vector();
            
            public 
    void paint(Graphics g) {
                
    Font font Font.getFont(Font.FACE_PROPORTIONALFont.STYLE_PLAINFont.SIZE_SMALL);
                
    g.setFont(font);

                final 
    int width getWidth();
                final 
    int fontHeight font.getHeight();
                final 
    int spaceWidth font.charWidth(' ');
                
                
    g.setColor(0x800000);
                
    g.fillRect(00widthgetHeight());
                
    g.setColor(0xffff00);

                
    int x 0;
                
    int y 0;
                
    synchronized (events) {
                    final 
    int count events.size();
                    for (
    int i 0counti++) {
                        
    String s = (String) events.elementAt(i);
                        
    int sw font.stringWidth(s);
                        if (
    sw width) {
                            
    0;
                            
    += fontHeight;
                        }
                        
    g.drawString(sxyGraphics.TOP Graphics.LEFT);
                        
    += sw;
                        
    += spaceWidth;
                    }
                }
            }

            public 
    void showNotify() {
                
    addEvent("sn");
            }

            public 
    void hideNotify() {
                
    addEvent("hn");
            }

            public 
    void sizeChanged(int wint h) {
                
    addEvent("sc");
            }

            public 
    void addEvent(String s) {
                
    synchronized (events) {
                    
    events.addElement(s);
                }
                
    repaint();
            }
        }

    On an N96, I get

    Code:
    sa sn
    on start up. (startApp, showNotify). After switching to a different task, and switching back, I see:

    Code:
    sa sn hn sn
    A hideNotify and showNotify have been added.

    On some Series 60 devices, you might get different results, depending on whether or not you include:

    Code:
    Nokia-MIDlet-Background-Event: pause
    This enables pauseApp() and startApp() events for background notification, on Series 60 3rd Edition FP2 and later.

    I don't have an N73 to test on.

    Graham.

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    5

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Thank you .

    The game finnally pause now !!!!
    I use hideNotify() as your test app does, it solves my problem.


    May I ask one more question:
    How to use "Nokia-MIDlet-Background-Event: pause"?
    I wrote it in my JAD like this, but the pauseApp() seems still not work.
    The JAD file like this:

    ==========
    NokiaPause.jad
    ------------------
    Code:
    Nokia-MIDlet-Background-Event: pause
    MIDlet-1: TestNokiaPause,,key
    MIDlet-Jar-URL: NokiaPause.jar
    MicroEdition-Configuration: CLDC-1.0
    MIDlet-Version: 1.0.0
    Nokia-MIDlet-Flip-Close: pause
    MIDlet-Name: NokiaPause Midlet Suite
    MIDlet-Vendor: Midlet Suite Vendor
    MicroEdition-Profile: MIDP-2.0
    ===============
    Much appreciate!!

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    That's correct, in the JAD, or in the MANIFEST in the JAR.

    However, it won't work on the N73. It is a new feature added in Series 60 3rd Edition Feature Pack 2, and the N73 is S60 3 (no feature pack).

    Graham.

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    5

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Thank you Graham for you help.

    ^_^

  14. #14
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    grahamhughes
    Event methods should not happen at the same time, since they come from a queue (some devices may allow this to happen, but very few).

    If the application goes into the background, some devices will call pauseApp(). If there is a Canvas on the screen, then the device may call hideNotify(). If it calls both, then it might call them in either order. So, hideNotify() might get called, with pauseApp() immediately after.

    For this reason, it is important to make sure that the code for putting the game into a "paused" state does not break if the game is already paused.

    Many Nokia devices never call pauseApp(). So far as I know, all Nokias call hideNotify().

    Also,I recommend against trying to stop and re-start Threads when the game pauses. This can have unexpected side-effects on some devices.

    Graham.
    could you elaborate on that issue, I mean why would there be a problem with stopping and restart a thread with wait and notify?

    should I ignore the update and paint methods when in pause mode but keep the thread running?

    Thanks,

    Adam.

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

    Re: How to pause the game when Incoming Call ? (The pauseApp,hideNofify doesn't work)

    Sure.

    The typical game code I'm talking about looks like this:

    PHP Code:
    private Thread thd;

    public 
    void run() {
        while (
    thd != null) {
            
    // game update loop

            
    repaint();
            
    serviceRepaints();
        }
    }

    public 
    void hideNotify() {
        
    // stop thread
        
    thd null;
    }

    public 
    void showNotify() {
        
    // start thread
        
    thd = new Thread(this);
        
    thd.start();

    Looks fine?

    One thing I should say: setting a variable of type Thread to null does not cause the thread to stop. In this code, the variable being set to null will be detected by the condition in the while loop, causing the loop to exit, and the run() method to exit too. Threads die when the run() method exits.

    The problem comes on devices that can't run code in the background, and have to suspend the VM the instant a call arrives. On these devices, the hideNotify() method won't get called when the call arrives. Instead, the application will receive hideNotify() and showNotify() events in rapid succession.

    The while loop in the run() method probably takes at least 50ms to get round. Since we're really talking about low-end devices, and therefore slower devices, it's probably more like 100ms (or more).

    If the hideNotify() and showNotify() occur, say, 10ms apart, then "thd" will be set to null, then set to reference the new thread before the loop sees the null. The loop, therefore, never ends, and the thread doesn't die.

    Meanwhile, showNotify() has created a new thread, and now two threads are running around the game update loop. Strange things now start to happen, and you have weird bugs don't make any sense.

    Potentially, you can stop and re-start the thread, but you have to do it very carefully, and really it's better to play safe and not bother.

    Paint events will just disappear while the MIDlet isn't displayed, so you don't have to do anything.

    All you need to do is detect the hideNotify(), and set the game into a "paused" state, in which it paints a pause-menu (with options like resume, quit, whatever), so that when the user returns to the app, nothing has happened and they can resume the game. You don't really need to do anything in showNotify().

    Graham.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: 2008-12-03, 02:25
  2. Answer Incoming Call doesn't work properly
    By mynick1000 in forum Symbian C++
    Replies: 37
    Last Post: 2008-05-13, 21:16
  3. Series 40 Sound and Incoming Call Confliction
    By jl1337 in forum General Development Questions
    Replies: 0
    Last Post: 2005-11-08, 09:26
  4. Getting a phone call in a game kills Midlet
    By EdHowson in forum Mobile Java General
    Replies: 8
    Last Post: 2003-03-31, 12:23
  5. Incoming call, 7650 and iPAQ
    By paller in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-03-19, 08:14

Posting Permissions

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