从地图视图中删除叠加层
我在 mapView 中创建叠加层,问题是当我再次返回 MapsView 活动时,我看到了之前制作的叠加层。我试图在 ondestroy 方法中删除覆盖,但这没有帮助。尝试了所有方法,相信我。这里是代码...另外在 onCreate() 中我使用了 mapView.invalidate();这也没有帮助。我只是想在活动完成后摆脱覆盖。有什么解决办法吗?
@Override
protected void onDestroy(){
super.onDestroy();
stopWorker=true;
mapView.invalidate();
mapView.postInvalidate();
for (int i=0; i<mapView.getOverlays().size(); i++ ) {
mapView.getOverlays().remove(i);
}
Toast.makeText(this,"map destroy ...", Toast.LENGTH_LONG).show();
mapView.getOverlays().clear();
}
I create overlays in mapView , the problem is when I get back to the mapsview activity again, i see the overlays that i previously made. i have tried to remove overlays in ondestroy method which doesnt help.Tried all, trust me.heres the code...Also in onCreate() i have used mapView.invalidate(); which doesnt help either. I just want to get rid of overlays when the activity is finished. Any solution?
@Override
protected void onDestroy(){
super.onDestroy();
stopWorker=true;
mapView.invalidate();
mapView.postInvalidate();
for (int i=0; i<mapView.getOverlays().size(); i++ ) {
mapView.getOverlays().remove(i);
}
Toast.makeText(this,"map destroy ...", Toast.LENGTH_LONG).show();
mapView.getOverlays().clear();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您的活动尚未完成。只有Activity结束后,才会进入onDestroy状态。尝试在 onPause() 或 onResume() 中编写相同的代码。
Seems like your activity is not getting Finished. Only if the Activity is finished, it will enter the onDestroy state. Try writing the same code in onPause() or onResume().
当您的活动完成时,叠加层会自动删除。您的代码中还有其他一些错误。例如,您可以通过按 HOME 来测试这一点,这不会触发
onDestroy()
。Overlays are automatically removed when your activity is finished. You have some other bug in your code. For example, you may be testing this by pressing HOME, which does not trigger
onDestroy()
.