为了检测地图移动和手势并使用我的地图项目的延迟加载支持,我正在尝试使用此库:http://code.google.com/p/mapview-overlay-manager/。
我已经设置了一个附加了overlayManager的地图,事件正好通过。我可以听听听众的祝酒。当我获得Application上下文时,它不是null。
我一直试图从ManagedOverlay类中启动一个intent。特别是在下面的onDoubleTap
方法中,我正在尝试启动一个intent,我收到此错误消息:
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我想我一般都明白我需要回调MapActivity子类并让它启动意图,或者我需要以不同的方式对上下文做些什么。然而,我无法解决具体问题。任何帮助表示赞赏。
public class SiteMapRev2 extends MapActivity {
private MapView mapView;
private OverlayManager overlayManager;
private MapController mapController;
private MyLocationOverlay userLocationOverlay;
private ArrayList<SiteSummary> sitesRoster = null;
private Drawable siteIcon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
overlayManager = new OverlayManager(this, mapView);
sitesRoster = new ArrayList<SiteSummary>();
userLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(userLocationOverlay);
mapController = mapView.getController();
mapController.setZoom(14);
siteIcon = this.getResources().getDrawable(R.drawable.marker2);
}
@Override
public void onStart() {
super.onStart();
Drawable defaultmarker = getResources().getDrawable(R.drawable.marker2);
ManagedOverlay managedOverlay = overlayManager.createOverlay("sites", defaultmarker);
managedOverlay.setOnOverlayGestureListener(new ManagedOverlayGestureDetector.OnOverlayGestureListener(){
public boolean onDoubleTap(MotionEvent arg0, ManagedOverlay arg1,
GeoPoint arg2, ManagedOverlayItem arg3) {
if (arg3 == null) {
return false;
}
else {
**SiteOverlayItem thisItem = (SiteOverlayItem) arg3;
String siteIDAsString = Integer.toString(thisItem.getSiteID());
Context c = getApplicationContext();
Intent showSiteDetails = new Intent(c,SiteDetailActivity.class);
Log.d(toString(), "intent = " + showSiteDetails.toString());
showSiteDetails.setData(Uri.parse(siteIDAsString));
c.startActivity(showSiteDetails);
return true;**
}
}
答案 0 :(得分:1)
将此标记设置为您的意图,Logcat太聪明,尝试了解对您说的内容;)
showSiteDetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
答案 1 :(得分:1)
我没有获取应用程序上下文,而是执行此操作:
SiteMapRev2.this.startActivity(showSiteDetails);
可以像往常一样从地图活动中启动活动。