×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  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
    Nokia Developer Champion
    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.

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

    Re: How to pause and resume the thread

    I know this. But my doubt is, if I passed entire array to addProximityListener() then addProximityListener() method can automatically checks all coordinates of array or I have to create five addProximityListener to check all five coordinates value..
    Last edited by Rahul More; 2013-03-26 at 10:35.
    Thanks & regards
    RAHUL.

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

    Re: How to pause and resume the thread

    You can't pass an array, because the signature of the method does not allow that. You must pass them one at a time, so five coordinates means five calls to addProximityListener(). What you DON'T need to have is five ProximityListeners. You can add the same Listener each time. When you get close to one of the targets, your listened receives the event, and one of the arguments to the method will be the coordinate you passed, so you know which target has triggered the event.

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

    Re: How to pause and resume the thread

    No. My application is Location based Reminder. In my app there are maximum five reminders can set that means five coordinates I have to check simultaneously and continuously... so how I do this by proximityListener??? Or if not then can you suggest me any other logic to do this...??
    Last edited by Rahul More; 2013-03-26 at 10:22.
    Thanks & regards
    RAHUL.

  10. #10
    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
    No.
    No what?

    Yes.

    Five coordinates. Five calls to LocationProvider.addProximityListener(). One listener. Five events.

    Code:
    private static final int PROXIMITY = 50;  // metres
    
    Coordinates[] targets = new Coordinates[5];
    
    // put the coordinates in the array here
    
    // then create a listener - we only need one
    ProximityListener myListener = new MyListener();
    
    // that set up the listener to watch five target coordinates
    for (int i = 0; i < targets.length; i++) {
        LocationProvider.addProximityListener(myListener, targets[i], PROXIMITY);
    }
    Don't forget Tiger79's warning about catching the LocationException from addProximityListener().

    Now, if all went well (no exceptions), then your proximity listener's proximityEvent() method will be called five times, as you reach each of the five targets. The event will get passed the particular Coordinate object you gave the LocationProvider, so that you know which of the five targets you reached.

    Go write some code and try it.

    Graham.

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

    Re: How to pause and resume the thread

    Ohhk Sir... thanx for the sample code.... I will try this... and i will get back to you....

    Quote Originally Posted by grahamhughes View Post
    Go write some code and try it.
    you are very experience in coding than me.. You always help me lot by giving accurate and helpful suggestions for my various questions and I appreciate that. I already wrote around more than 1000 line of code by self for my this project and without help from my teachers and friends. I insist you to show this code because I have very little knowledge about ProximityListener and about its working and According to your suggestions I searched a lot on google but whatever search result i got is all showing same thing for one coordinates and was unable to clear my doubt. I am new in J2ME development and this Location API and my project viva is comming soon, so i have very little time in my hand that's why I asked you & insist you... Once again Thanx for the code snippet
    Last edited by Rahul More; 2013-03-26 at 11:45.
    Thanks & regards
    RAHUL.

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

    Re: How to pause and resume the thread

    I have one doubt in this. Suppose after registering some coordinates to proximityListener... if I want to change the proximityRadius.... then it is possible to change the proximityRadius of register coordinates???
    Thanks & regards
    RAHUL.

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

    Re: How to pause and resume the thread

    What problem would you solve by changing it?

    Yes, you can do it by removing the ProximityListener, then re-adding it with all the targets using the new proximity.

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

    Re: How to pause and resume the thread

    Because I added a feature in my project which gives flexibility to change the ProximityRaduis according to user convenience.. so if user change ProximityRaduis from 30 to 50 then there is a possibility to change ProximityRaduis of already register coordinates???
    Thanks & regards
    RAHUL.

  15. #15
    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
    so if user change ProximityRaduis from 30 to 50 then there is a possibility to change ProximityRaduis of already register coordinates???
    No, but you can remove them and re-register them with a new radius as I wrote in my previous post.

    Quote Originally Posted by Rahul More View Post
    Because I added a feature in my project which gives flexibility to change the ProximityRaduis according to user convenience..
    I see no reason why a user would want such a feature. Why would they change it? What is the "convenience"? Most likely, they'd make it smaller, in an attempt to make it "more accurate", and probably stop the application from working.

    I suggest you embrace some agile principles. The principle I most like to promote is "Simplicity--the art of maximizing the amount of work not done". When developers on my team invent new features, I make them aware that they have displeased me. "Developer gold plating" costs money and threatens on-time delivery without adding demonstrable business value.

    Make sure you get the important requirements met, tested and done (when I say "done", I mean "done"" - as in, you are not going to touch is again), before you consider "nice to haves".

    Graham.

Page 1 of 2 12 LastLast

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 C++
    Replies: 1
    Last Post: 2011-02-04, 15:12
  3. Music player pause & resume
    By mobi1 in forum Symbian C++
    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
  •