×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    28

    Thread and CommandListener

    Hello,

    I have a thread running in my application and to stop it I need to access Menu and the Item Stop. It works fine on my Nokia
    phone, but sometimes I get problem on Emulator. And also few users reported they got problem to stop the application on
    their phones. But the most users have no problem with this.

    So I am wondering what is the standard solution for this. Actually the thread is running in background and I should be able to do whatever I want with my application? Is there any problem with CommandListener? How do you solve situations like
    this?

    Thank you

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

    Thumbs up Re: Thread and CommandListener

    Hi,

    What do you means by stoping the application..
    Are you pausing the application or you are exiting the application.

    If you are pausing the application then what issue it is showing.Else if you are exiting the application then what issue you have..please provides this information.

    Thanks
    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 2008
    Posts
    28

    Re: Thread and CommandListener

    What I mean is this. There is animation running in one thread and if I want to stop it, I use command Stop from Menu.

    They dont stop the application, just the animation, it was mistake what I wrote there.

    So I am wondering if there is problem in my code or in their phones and incompatibility with J2ME standards.

    Maybe I wrote it too complicated, but the question is easy: When I let run animation in thread, can I access the Command Listener and stop the animation?

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    17

    Re: Thread and CommandListener

    Hi

    My opinion is

    put your code of animation in separated class that implement Runnable
    i.e

    public class MyAnimation implements Runnable
    {
    boolean runFlag=false,stopFlag=false;
    public void run()
    {
    if(runFlag)

    showAnnimation();
    else
    if(stopFlag)

    stopAnimation();

    }

    private void showAnnimation()
    {
    //put your code here

    //reset
    runFlag=false
    }

    private void stopAnimation()
    {
    //put your code here


    //reset
    stopFlag=false;
    }
    }


    in your midlet

    Thread animation=new MyAnimation();

    ,
    inside Command listener

    if(command==playAnimation)
    {
    animation.runFlag=true;
    animation.start();
    }
    else
    {
    if(command==stopAnimation)
    {
    animation.stopFlag=true;
    animation.start();
    }
    }

    Best Regards
    Nabil

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    28

    Re: Thread and CommandListener

    Thank you, actually the problem is not to stop the animation, but to access the Command Listener.

    If the animation is running, its difficult to open the Menu and to click the Item Stop animation. This is what I mean its difficult to stop the animation on Emulator. Once I click the Stop animation Command, it will stop immediately.

    I use code like this (simplified)

    class Animation extends Canvas implements Runnable, CommandListener

    paint() method:
    //if flag runAnimation:
    //draw next image from imageArray[]
    //display.callSerially(this)

    run() method:
    // wait 100 ms
    // repaint



    The rest is similar to your code. But I dont use the class Thread there. Maybe I should use it and set Priority LOW?
    I have this problem only on Emulator, on my phone there is no problem.
    I will try your code and see if it was the problem, that I put everything inside one class (to keep it small).

Similar Threads

  1. Thread and MMS
    By mirkenken in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-03-04, 08:25
  2. new thread crashes app on Nokia6680
    By humarkus in forum Mobile Java General
    Replies: 1
    Last Post: 2006-01-20, 16:27
  3. Synchronization of thread connection with CommandListener
    By olegon in forum Mobile Java General
    Replies: 8
    Last Post: 2005-12-15, 13:42
  4. Problem with the Nokia 6600, Bluetooth and Monty Thread
    By tenfourty in forum Mobile Java General
    Replies: 15
    Last Post: 2005-09-30, 14:15
  5. Nokia emulators hanging on HTTP thread
    By kibi1 in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

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