Gps Updates, View blocked

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

Gps Updates, View blocked

Postby ArtworkAD » Sat Aug 07, 2010 4:53 pm

Hi,
I have a class that gets gps data. everytime the gps location is updated a update handler gets a UDATE_LOCATION message, and within the update handler I am able e.g. to set a textview and show some gps data. The update handler itself is located in the MainActivity. So the problem is that the view, the ui thread is blocked for some secs.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onLocationChanged(Location location) {
  3.                 location = this.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  4.                 try {
  5.                         this.mLongitude = location.getLongitude();
  6.                         this.mLatitude = location.getLatitude();               
  7.                         Message msg = Message.obtain();
  8.                         msg.what = UPDATE_LOCATION;
  9.                         this.SystemService.gtask.updateHandler.sendMessage(msg);
  10.                 } catch (NullPointerException e) {
  11.                         Log.i("Null pointer exception " + mLongitude + "," + mLatitude, null);
  12.                 }
  13.         }      
  14.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

and
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Handler updateHandler = new Handler() {
  2.                 /** Gets called on every message that is received */
  3.                 // @Override
  4.                 public void handleMessage(Message msg) {
  5.                         switch (msg.what) {
  6.                                 case UPDATE_LOCATION: {
  7.                                         if(geosenseo.getCurrentPoint() == null){
  8.                                                 streetView.setText("locating...");
  9.                                         }else{
  10.                                                 streetView.setText(geosenseo.getCurrentStreet());
  11.                                                 cityView.setText(geosenseo.getCurrentCity());
  12.                                         }
  13.                                 }
  14.                     }
  15.                         super.handleMessage(msg);
  16.                 }
  17.              };
  18.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

in the "case UPDATE_LOCATION" part the view hangs-.-

I thougt about apply a thread or something but I can not really imagine how to do this. please help!
ArtworkAD
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jul 29, 2010 7:56 pm

Top

Re: Gps Updates, View blocked

Postby blundell » Sun Aug 08, 2010 6:37 pm

You should put geosenseo.getCurrentStreet() and geosenseo.getCurrentCity() into another thread with a handler callback, as when you hit case UPDATE_LOCATION you UI thread is attempting to set the TextView but first it has to go off and do these methods.

Therefore as I said if you do these methods in a thread then set the textview when you return you will have no lag.

There are a few threads on anddev about starting threads have a look at this for some example code:
other-coding-problems-f5/asynctask-help-loading-progress-dialog-t16474.html?hilit=progressDialog#p50693
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Map Problems

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests