×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Is This Code Correct????

    i wanna display for example an Alert To Say good Bye When The User Click On exitCommand but the SDK gives Exception

    I tried That

    Code:
    
    if(c==exitCommand){
                Thread th = new Thread() {
                    public void run() {
                        
                            Alert alert=new Alert("","Good Bye",null,AlertType.CONFIRMATION);
    
                        alert.setTimeout(5000);
                        display.setCurrent(alert, loginForm);
                         
                    }
                };
                
                th.start();
                th.notifyAll();
                quitApp();
            }

    why Is That Wrong?
    Let The Impossible Happen!!!

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

    Re: Is This Code Correct????

    What exactly the error you are facing inside that code?
    Explain the issue are you facing in much more details.

    On pressing the command exit, you can simply display the alert and there is no need to put the code inside the thread,
    Last edited by raj_J2ME; 2011-01-07 at 11:20. Reason: spell
    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: Is This Code Correct????

    Quote Originally Posted by raj_J2ME View Post
    What exactly the error you are facing inside that code?
    Explain the issue are you facing in much more details.

    On pressing the command exit, you can simply display the alert and there is no need to put the code inside the thread,
    When i do that it display the alert but after it not exit The midlet this is the problem
    Let The Impossible Happen!!!

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Is This Code Correct????

    i presume your exception is illegalstateexception, which is raised, according to the documentation, by notifyAll() if your thread does not own the lock (which you obtain by synchronising your code block).
    anyway, your code would never do what you wish, it would simply run an alert in a seperate thread and exit at the same time.
    if you need a confirmation before your user exit the application, you should use a command with a commandlistener, and you don't need a thread.
    by the way, what does your quitApp method does exactly ?

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

    Re: Is This Code Correct????

    quitApp() method contain
    destroyApp(true);
    notifyDestroyed();

    any way , i want the quit of midlet wait until this thread complete or any other thread

    The Question is:

    How to make any Process wait Until defined Thread completed That is what i want to know

    thanks njzk2 for replying
    Let The Impossible Happen!!!

  6. #6
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Is This Code Correct????

    you don't need your process to wait until a thread completes, since all display methods are non-blocking.

    basically, you probably will have to do with another type of screen to display the message, probably a Form, with a command and a command listener to actually quit

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

    Re: Is This Code Correct????

    Quote Originally Posted by njzk2 View Post
    you don't need your process to wait until a thread completes, since all display methods are non-blocking.

    basically, you probably will have to do with another type of screen to display the message, probably a Form, with a command and a command listener to actually quit
    Code:
    if(c==exitCommand){
                 th = new Thread() {
                    public void run() {
    
                            Alert alert=new Alert("","dds",null,AlertType.CONFIRMATION);
    
                        alert.setTimeout(5000);
                        //display.setCurrent(alert, loginForm);
    
                    }
                };
                th.start();
    
                while (!th.isAlive()) {
        // Thread has not finished
                   /* Alert alert=new Alert("","dds",null,AlertType.CONFIRMATION);
    
                        alert.setTimeout(1000);
                        display.setCurrent(alert, loginForm);*/
    
    
        // Finished
                    quitApp();
    }
    i tried that not giving error but also doesn't work doesn't quit
    Let The Impossible Happen!!!

Similar Threads

  1. which one is correct!!!!!!!!
    By abhinash2009 in forum Symbian
    Replies: 10
    Last Post: 2010-03-26, 13:11
  2. is this code correct ?
    By honest_success in forum Near Field Communication
    Replies: 27
    Last Post: 2009-06-25, 09:10
  3. please correct my code
    By honest_success in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2007-09-12, 21:55
  4. can u correct me
    By praveena in forum Symbian User Interface
    Replies: 2
    Last Post: 2005-09-29, 08:26
  5. Replies: 0
    Last Post: 2003-09-26, 15:07

Posting Permissions

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