Do "adb shell cat /data/anr/traces.txt" to see what your app was busy doing at that point. This is the very first step you need to take: understand what your app is doing that is causing the ANR.
The next step I would take from that, if it is not enough to solve the problem, is profile your app. Note that the ANR dialog happens after your application has been unresponsive for 5 seconds. This is a heck of a long time. On Mon, Jun 27, 2011 at 7:32 AM, Boozel <boozelcl...@gmail.com> wrote: > Hi i'm trying to draw an overlay onto a google map but i sometimes get an > ANR "Reason: keyDispatchingTimedOut ". > Can any one tell me what the best structure is to do the drawing and > prevent this? > My code is below. Thanks in advance for any help > > public class MyMap extends MapActivity { > /** Called when the activity is first created. */ > DBHelper dbhelp; > final String TAG = "SignalSpot"; > String [][]rows; > MapView mapView; > Paint mPaint; > Handler serviceHandler; > RunTask rt; > MyLocationOverlay myLocationOverlay; > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.map); > > dbhelp = new DBHelper(this); > > refreshHeatmapData(); > //TODO periodically refresh heatmap > > mapView = (MapView) findViewById(R.id.mapview); > mapView.setBuiltInZoomControls(true); > > myLocationOverlay = new MyLocationOverlay(this, mapView); > mapView.getOverlays().add(myLocationOverlay); > > serviceHandler = new Handler(); > rt = new RunTask(); > serviceHandler.postDelayed(rt ,5*1000); > > myLocationOverlay.enableMyLocation(); > > mapView.getOverlays().add(new MyOverlay()); > } > > @Override > public void onDestroy() > { > super.onDestroy(); > myLocationOverlay.disableMyLocation(); > serviceHandler.removeCallbacks(rt); > } > > public void refreshHeatmapData() > {rows = dbhelp.getAllRows(-1);} > > > @Override > protected boolean isRouteDisplayed() { > return false; > } > class MyOverlay extends Overlay{ > public MyOverlay(){} > > public void draw(Canvas canvas, MapView mapv, boolean shadow){ > super.draw(canvas, mapv, shadow); > > Projection p = mapv.getProjection(); > > Log.i(TAG,"MAP NO OF ROWS: "+rows.length); > > for(int i=0;i<rows.length;i++) > { Log.i(TAG,"ACtual Data to draw: "+rows[i][2]+", "+rows[i][3]); > int x = (int)(Double.parseDouble(rows[i][2])*1E6); > int y = (int)(Double.parseDouble(rows[i][3])*1E6); > Log.i(TAG,"Drawing point No:"+i+" @ "+x+","+y); > GeoPoint in = new GeoPoint(x,y); > Log.i(TAG,"GEO POINT- lat: "+in.getLatitudeE6()+", lon: > "+in.getLongitudeE6()); > Point pixels = p.toPixels(in,null); > double ss = Double.parseDouble(rows[i][4]); > //test code for constant circle when zooming > float radius = p.metersToEquatorPixels(100); > > RadialGradient g = new RadialGradient(pixels.x, pixels.y, > radius,getColor2(ss) , null,TileMode.CLAMP); > > Paint gp = new Paint(); > gp.setShader(g); > //myCanvas.drawCircle(x, y, radius, gp); > > canvas.drawCircle(pixels.x, pixels.y, radius, gp); > > } > > } > } > class RunTask implements Runnable > { > public void run() > { Log.i(TAG,"Map data refresh run task"); > refreshHeatmapData(); > serviceHandler.postDelayed( this, 5*1000 ); > } > } > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en