×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Pausing and Resuming j2me application and it's working

    Through posts I came to know that in pauseApp() method of j2me should be the code for releasing resources so that it may no affect the phone battery, etc. What I want to know is that how can I make my application to start working from the same point from where it was paused?
    I have a j2me application which receives chunks of Messages from server and then operates (decodes into proper formate) and writes that data as contacts into the device memory. Everything works fine if there is no interruption, but as I receive a call and application is processing (writing contacts) it stops there, no matter if I reject the call or so, it doesn't move further from there. What I want to do is to make it work the same way as it was before call. How can I do so? I need logic to perform it, what sources do I need to release in pauseApp() and how to reset them back when call is ended? Need that idea, thanks

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

    Re: Pausing and Resuming j2me application and it's working

    OK... you do not need to do anything.

    There is no point in adding code to pauseApp(), as no Nokia device ever calls pauseApp().

    If you are having a problem after a call, I would imagine that your network code is throwing an exception (which you are swallowing) because it can't open a connection during a call (or because its connection is forcibly closed), and leaving the code in a state where it cannot continue.

    Make sure you catch IOExceptions in your netwok code and handle them usefully.

    Graham.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by grahamhughes View Post
    OK... you do not need to do anything.

    There is no point in adding code to pauseApp(), as no Nokia device ever calls pauseApp().

    If you are having a problem after a call, I would imagine that your network code is throwing an exception (which you are swallowing) because it can't open a connection during a call (or because its connection is forcibly closed), and leaving the code in a state where it cannot continue.

    Make sure you catch IOExceptions in your netwok code and handle them usefully.

    Graham.
    You mean to say all I can do is to show caught exception and terminate process there (which is actually already terminated by the OS) and ask user to restart the process and I have nothing to do? In short no way to process how I want it?

    But if I remember I use to receive SMS during my normal call procedure, that means phone does that in normal behaviour, then why not in application? Any particular reason?

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

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by saqibatiq View Post
    You mean to say all I can do is to show caught exception and terminate process there
    No... I mean you need to catch the exception so that the process does not terminate.

    Do you know what exception is being thrown and from where?

    Quote Originally Posted by saqibatiq View Post
    But if I remember I use to receive SMS during my normal call procedure, that means phone does that in normal behaviour, then why not in application?
    Is your application receiving SMS?

    Graham.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by grahamhughes View Post
    No... I mean you need to catch the exception so that the process does not terminate.

    Do you know what exception is being thrown and from where?
    Well I guess below info may give answer of your question!!!

    Quote Originally Posted by grahamhughes View Post
    Is your application receiving SMS?

    Graham.
    Yes my application receives SMS what I mentioned as [MESSAGES FROM SERVER] in my post. So it may clear now that how can I keep my process continue after resume. And it doesn't throw any exception because process doesn't terminates but it just stands over there and waits for time out (which I actually handled)

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

    Re: Pausing and Resuming j2me application and it's working

    How are you waiting for a message? By using MessageConnector.receive(), or a MessageListener? Perhaps the specific fragment of code would help...

    I'm guessing you are using receive(), in which case either it returns a Message object, or it throws an Exception...

    I need to know more about what is happening in your code.

    Oh, would also be useful to know what device you are running this on.
    Last edited by grahamhughes; 2013-04-09 at 20:49.

  7. #7
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by grahamhughes View Post
    How are you waiting for a message? By using MessageConnector.receive(), or a MessageListener? Perhaps the specific fragment of code would help...

    I'm guessing you are using receive(), in which case either it returns a Message object, or it throws an Exception...

    I need to know more about what is happening in your code.

    Oh, would also be useful to know what device you are running this on.
    Yes I am waiting through receive() method what happens in my code I have already explained in my question. Once again in short I receive a number of messages from Server side to mobile port in my application which further decodes it and then stores contact into memory. The process hangs when any call (phone call) interrupts the process and it doesn't move further. For the receive() method to end up I start a thread and wait for 60 seconds if I don't receive any further message I quite. But the thing as you know I have to open port for receiving message so I want to ask does it closes that port or what when a call happens?
    And I am using this application over Nokia X2-02, X2-05 and Asha 302. Thanks

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

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by saqibatiq View Post
    The process hangs when any call (phone call) interrupts the process and it doesn't move further.
    Where does it hang? Are you saying that receive() blocks and never returns?

    Quote Originally Posted by saqibatiq View Post
    For the receive() method to end up I start a thread and wait for 60 seconds if I don't receive any further message I quite.
    How do you quit?

    Quote Originally Posted by saqibatiq View Post
    does it closes that port or what when a call happens?
    If the connection closes, receive() should throw an IOException. You are telling me that this doesn't happen.

    Can you post some code, please? I'd like to reproduce the issue here, and I need to make sure I'm doing the same as you.

    What are you displaying on the screen when the application runs? What class of Displayable?

    Graham.

  9. #9
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by grahamhughes View Post
    Where does it hang? Are you saying that receive() blocks and never returns?



    How do you quit?



    If the connection closes, receive() should throw an IOException. You are telling me that this doesn't happen.

    Can you post some code, please? I'd like to reproduce the issue here, and I need to make sure I'm doing the same as you.

    What are you displaying on the screen when the application runs? What class of Displayable?

    Graham.
    This is what I am asking to you that if I have opened a port and listening to it continuesly and operating different operations over received messages, and I get a call in between what happens then to the opened port or receiving of messages because my process doesn't move ahead then and nor I get any kind of exception to know that which part of the process was interrupted by the call. Talking about the code it's quite lengthly but all you can consider is that my app opens port, when receives a message I save it, and through a thread I keep on listening for message receive for upto 60 seconds. Now just tell me what happens to port and thread when I receive a phone call? Because I think it just stops everything and I am unable to proceed. Thanks

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

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by saqibatiq View Post
    Now just tell me what happens to port and thread when I receive a phone call?
    I can tell you what happens to the Thread... absolutely nothing. Apps usually continue quite happily after the call without any special code to do anything.

    I think something is happening in your code that you don't realize, and I'm trying to help you find out what, so we can fix it. I need more information that you're giving me. OK, I'll write an example at the weekend...

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

    Re: Pausing and Resuming j2me application and it's working

    OK...

    Here's my code (both sending and receiving apps). I tried the Receive app on a Nokia C3-01 - the closest I have to the devices you're using. I sent two messages, then called the phone (accepting the call), then terminated the call and sent a third message (without restarting the Receive app). All three messages were received.

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import javax.wireless.messaging.*;
    
    public class Receive extends MIDlet implements CommandListener, Runnable {
        private static final int PORT = 16666;
        
        private static final Command EXIT = new Command("Exit", Command.EXIT, 1);
    
        private Form form;
        private MessageConnection con;
        
        public void startApp() {
            if (form == null) {
                form = new Form("Receive");
                form.addCommand(EXIT);
                form.setCommandListener(this);
                Display.getDisplay(this).setCurrent(form);
                (new Thread(this)).start();
            }
        }
    
        public void commandAction(Command c, Displayable d) {
            if (c == EXIT) {
                try {
                    con.close();
                } catch (Exception e) {
                    // swallow
                }
                notifyDestroyed();
            }
        }
    
        public void run() {
            try {
                con = (MessageConnection) Connector.open("sms://:" + PORT);
                println("Listening...");
                while (true) {
                    Message m = con.receive();
                    if (m instanceof TextMessage) {
                        println(((TextMessage) m).getPayloadText());
                    } else {
                        println("[non-text]");
                    }
                }
            } catch (Exception e) {
                println(e);
            } finally {
                println("Stopped listening.");
            }
        }
    
        private void println(Object o) {
            form.append((o.toString()) + "\n");
        }
    
        public void pauseApp() {
        }
        public void destroyApp(boolean b) {
        }
    }
    Code:
    import java.io.*;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import javax.wireless.messaging.*;
    
    public class Send extends MIDlet implements CommandListener {
    
        private static final int PORT = 16666;
        
        private static final Command EXIT = new Command("Exit", Command.EXIT, 1);
        private static final Command SEND = new Command("Send", Command.OK, 1);
    
        private Form form;
        private TextField message;
        private TextField number;
    
        public void startApp() {
            if (form == null) {
                form = new Form("Send");
                form.addCommand(EXIT);
                form.addCommand(SEND);
                message = new TextField("Message", "", 140, TextField.ANY);
                form.append(message);
                number = new TextField("Send to", "+", 20, TextField.PHONENUMBER);
                form.append(number);
                form.setCommandListener(this);
                Display.getDisplay(this).setCurrent(form);
            }
        }
    
        public void commandAction(Command c, Displayable d) {
            if (c == EXIT) {
                notifyDestroyed();
            } else if (c == SEND) {
                send();
            }
        }
    
        private void send() {
            println("Sending...");
            try {
                MessageConnection con = (MessageConnection) Connector.open("sms://" + number.getString() + ":" + PORT);
                try {
                    TextMessage msg = (TextMessage) con.newMessage(MessageConnection.TEXT_MESSAGE);
                    msg.setPayloadText(message.getString());
                    con.send(msg);
                    println("Sent.");
                } finally {
                    con.close();
                }
            } catch (IOException e) {
                println(e);
            }
        }
        
        private void println(Object o) {
            form.append((o.toString()) + "\n");
        }
    
        public void pauseApp() {
        }
        public void destroyApp(boolean b) {
        }
    }

  12. #12
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by grahamhughes View Post
    the closest I have to the devices you're using. I sent two messages, then called the phone (accepting the call), then terminated the call and sent a third message (without restarting the Receive app). All three messages were received.
    There is a little I want to clarify that I am receiving messages and there is no pause, then call, then again receive. What I am talking about is continues receiving of messages and in between that I receive a phone call that Halts the process. (And not only receiving messages but processing over those messages, like making then in proper format and then writing contacts into the device memory) One thing might need to be taken care that it could work for a 1, 2 or 3 messages (little number) but for my app which receives more than 15+ messages in a process that could be the real issue.

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

    Re: Pausing and Resuming j2me application and it's working

    Sorry, I'm getting confused as to what your problem is.

    You said originally that your code works, then you receive a phone call on the device, and afterwards the code does not work.

    In my test, with the code I gave, the code works, I receive a phone call, and afterwards the code still works.

    Does my test code work for you?

  14. #14
    Registered User
    Join Date
    Nov 2012
    Location
    Lahore, Pakista
    Posts
    58

    Re: Pausing and Resuming j2me application and it's working

    Quote Originally Posted by grahamhughes View Post
    Sorry, I'm getting confused as to what your problem is.

    You said originally that your code works, then you receive a phone call on the device, and afterwards the code does not work.

    In my test, with the code I gave, the code works, I receive a phone call, and afterwards the code still works.

    Does my test code work for you?
    Sorry for late reply, your code is almost the same what I am using, the only issue is that it works for little number of messages received and interruption occurred during, if say I have 40 messages to receive and after 20 messages I receive a call and for 1 minute pause I come back to application (while in back messages continued to be sent by server over my phone port) and then I see process is halted where it was before call received. That's what I know! Thanks

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

    Re: Pausing and Resuming j2me application and it's working

    Two questions - I'm looking for yes/no answers.

    1. Did you try running my code, and sending 40 messages with a one minute phone call after 20?

    2. Did it stop working?

    I will try reproducing your problem, but before I sit and send (and pay for!) 40 text messages, I'd like to be sure you've tried it already and that you can reproduce the problem.

    Graham.

Similar Threads

  1. Please help: Resuming application in the background
    By B.Adams in forum [Archived] Flash Lite on Nokia Devices
    Replies: 1
    Last Post: 2011-05-21, 05:06
  2. pausing j2me app when using platformrequest
    By vempatisurya in forum Mobile Java General
    Replies: 4
    Last Post: 2010-09-28, 14:21
  3. Resuming a background midlet application
    By yuenfatt in forum Symbian
    Replies: 0
    Last Post: 2009-02-23, 04:08
  4. pausing and resuming games
    By ayushv2005 in forum Mobile Java Games
    Replies: 5
    Last Post: 2008-06-15, 19:53
  5. Pausing/resuming full screen midlet
    By dubick in forum Mobile Java General
    Replies: 0
    Last Post: 2002-11-15, 11:03

Posting Permissions

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