×

Discussion Board

Results 1 to 15 of 18

Hybrid View

  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Question How to pause and resume the thread

    In my j2me app I have an array of double data type containing 5 coordinates value. This array is inside the thread to continuously check whether the same values is given by GPS. Once it get correct match, I want to pause the thread then remove match found value from thread and resume the thread. I want this should be happen till array contains coordinates values. Once array got empty I want to pause the thread till it get new value, Once again when array gets values it should start again.. How should I implement this logic in code.. anybody had done this or tried similar code before then please share your ideas or code...
    Thanks & regards
    RAHUL.

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

    Re: How to pause and resume the thread

    I suggest you don't do it this way.

    Use a ProximityListener, so that you only get location information from the LocationProvider when you are close to one of your target points.

    Note that with GPS coordinates, you must think in terms of "close", not "the same". GPS readings are not exact. You need to regard "within 20 metres of target" (for example) as "target reached".

    For example:

    Code:
    if (target.getLatitude() == whereIamNow.getLatitude() && target.getLongitude() == whereIamNow.getLongitude()) {
        // it is likely that the condition above will never be true
    }
    For this code to work, you'd need a 100% accurate GPS (which doesn't exist) and be standing in the correct place, to the nanometre. Or be one-in-a-million lucky that the inaccuracy happened to give you the right result.

    You could work out the distance between the target and current locations yourself, but the math is not trivial, and the proximity listener mechanism will automatically work it out for you, and tell you only when you're within the specified range. And by using the Listener mechanism, you don't need your own thread.

    Graham.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Re: How to pause and resume the thread

    I want to run this mechanism continuously in the background(even after app got hide) that's why I am thinking to use thread..
    According to your suggestion I have to use ProximityListner but in this article(http://www.developer.nokia.com/Commu...ner_in_Java_ME) there is line - The proximity registration for these coordinates is cancelled as soon as the the proximityEvent is called. If the application should be notified again, a new ProximityListener registration is required.. That means this will work only for one coordinate value. I want to check my 5 coordinates values which is present in array. How should I do this??
    Last edited by Rahul More; 2013-03-24 at 04:00.
    Thanks & regards
    RAHUL.

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

    Re: How to pause and resume the thread

    Quote Originally Posted by Rahul More View Post
    I want to run this mechanism continuously in the background(even after app got hide) that's why I am thinking to use thread..
    You can still receive events in the background. You don't need a Thread.

    Quote Originally Posted by Rahul More View Post
    That means this will work only for one coordinate value.
    No, it will work for each Coordinate object once. So, you register five targets. When you reach one of them, you will receive an event, and that proximity request will be cancelled. It has to, or you would start receiving a whole stream of "we're here!" events. The other four proximity requests remain active, until you reach them too.

    I suggest you try it in a simple test MIDlet. You only need 20 or 30 lines of code.

    Graham.

  5. #5
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Re: How to pause and resume the thread

    Ok... sir...but I am storing five coordinates into an array, so how I register five coordinates???
    Thanks & regards
    RAHUL.

  6. #6
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: How to pause and resume the thread

    you can add multiple locations with the following instruction : LocationProvider.addProximityListener
    You can do that multiple times, for example for the whole length of your array... Just keep in mind to do that in a try-catch block because it might throw a LocationException whenever no more extra porximitylisteners are allowed on a specific platform...
    Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them.

Similar Threads

  1. Replies: 3
    Last Post: 2012-09-11, 07:00
  2. Play, Pause and Resume in Video Streaming.
    By somnathbanik in forum Symbian
    Replies: 1
    Last Post: 2011-02-04, 15:12
  3. Music player pause & resume
    By mobi1 in forum Symbian
    Replies: 8
    Last Post: 2007-09-19, 10:08
  4. How to pause and resume in CMMFDevSound
    By junhuali in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2007-05-14, 16:58
  5. Correctly pause and resume MIDlet?
    By Terol in forum Mobile Java General
    Replies: 2
    Last Post: 2002-08-05, 06:25

Posting Permissions

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