Refresh Thread, Redrawing Overlays

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Refresh Thread, Redrawing Overlays

Postby MrLondon » Wed Dec 23, 2009 8:48 pm

So I have a fully functional mapview activity I currently use a refresh button call the method below to redraw overlays based on coordinates which works fine. I would like to be able to auto-refresh it using a thread. By auto-refresh, I would like to redraw my overlays by calling the method below every x amount of seconds from a thread.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private void addOverlaysToMap() {
  3.  
  4.                 final List<Overlay> overlays = mapView.getOverlays();
  5.  
  6.                 overlays.clear();
  7.  
  8.                 normalItems.clear();
  9.  
  10.                 warningItems.clear();
  11.  
  12.                 overlays.add(myLocationOverlay);
  13.  
  14.  
  15.  
  16.                 Cursor cursor = getContentResolver().query(Tracker.Locations.CONTENT_URI,
  17.  
  18.                         new String[]{Tracker.Locations._FID, Tracker.Locations.LOCATION, Tracker.Locations.UPDATE_TIME},
  19.  
  20.                         null, null, null);
  21.  
  22.                 if (cursor.getCount() > 0) {
  23.  
  24.         // builds all the overlay  items
  25.  
  26.         // convert to overlays
  27.  
  28.                     convertGPRMCToOverlayItems(cursor);
  29.  
  30.                 }
  31.  
  32.                 cursor.close();
  33.  
  34.                 if (warningItems.size() > 0) {
  35.  
  36.                     overlays.add(warningItems);
  37.  
  38.                 }
  39.  
  40.                 if (normalItems.size() > 0) {
  41.  
  42.                     overlays.add(normalItems);
  43.  
  44.                 }
  45.  
  46.             }
  47.  
  48.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Because I am receiving coordinates it is essential to refresh every x amount of seconds. When I create a separate class for the refresh thread everything works fine but it randomly crashes with an uncaught exception.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.      class refreshTicker implements Runnable{
  5.  
  6.           public void run() {
  7.  
  8.                while(!Thread.currentThread().isInterrupted()){
  9.  
  10.                          DisplayLoc.this.addOverlaysToMap();
  11.  
  12.                     try {
  13.  
  14.                          Thread.sleep(3000);
  15.  
  16.                     } catch (InterruptedException e) {
  17.  
  18.                          Thread.currentThread().interrupt();
  19.  
  20.                     }
  21.  
  22.                }
  23.  
  24.           }
  25.  
  26.     }
  27.  
  28.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

Any suggestions?
MrLondon
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon Jul 20, 2009 9:26 pm
Location: CO

Top

Postby MrLondon » Thu Dec 31, 2009 1:38 am

Anyone???
MrLondon
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon Jul 20, 2009 9:26 pm
Location: CO

Postby gostyloj » Tue Jan 12, 2010 6:48 pm

This is what I would do:

Set up a Handler to handle a message. I don't think this is technically a Thread, but it will work the same way.

overlayRefreshHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case REFRESH:
DisplayLoc.this.addOverlaysToMap();
break;
}
};

Then set up your message on a timer:
Message msg = new Message();
msg.what = REFRESH;
overlayRefreshHandler.sendMessageDelayed(msg, 3000);


If you have some experience in Map overlays would you mind looking at my recent issue post:
http://www.anddev.org/memory_leak_in_ma ... 10244.html
gostyloj
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 28, 2009 12:52 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 7 guests