我不清楚如何在Android中工作的程序。我最近两个月开始从事Android工作,同时也是Java初学者。所以,我正在努力发展和学习。这是我实现的代码片段,我不太清楚它是如何按照我的要求工作的。活动的生命周期是什么?
activity{
onCreate(){
/* here i am using google maps api and trying to plot the current location*/
OverlayItem overlayItem1 = new OverlayItem(ourLocation,"Our Location","Position");
CustomPinpoint custom1 = new CustomPinpoint(d, Activity.this);
custom1.insertPinpoint(overlayItem1);
overlayList.add(custom1);
controller.animateTo(ourLocation);
}
private class TouchOverlay extends com.google.android.maps.Overlay{
public boolean onTouchEvent(MotionEvent event, MapView map){
onZoom();
}
}
public boolean onCreateOptionsMenu(Menu menu){}
public boolean onOptionsItemSelected(MenuItem item){
case.X:
getGPSPoints();//Here i will be getting some gps points from stored database
// and I would like to plot them all on the map.
TouchOverlay touchOverlay = new TouchOverlay();
overlayList.add(touchOverlay);
}
onPause(){
super.onPause();
lm.removeUpdates(this);
}
onResume(){
super.onResume();
lm.requestLocationUpdates(towers, 500, (float) 0.5, this);
}
onLocationChanged(Location l) {
// TODO Auto-generated method stub
clearmap();
lat = (int) (l.getLatitude()*1E6);
longi = (int) (l.getLongitude()*1E6);
GeoPoint ourLocation = new GeoPoint(lat, longi);
CustomPinpoint custom = new CustomPinpoint(d, TrafficMapActivity.this);
OverlayItem overlayItem = new OverlayItem(ourLocation,"Our location","Position");
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
}
}
我的问题是,当将onLocationChanged
方法被调用,也的onTouchEvent方法?
我已经创建了一个方法来getGPSPoints()
,我想绘制在地图上获得的点。我的意图是它像谷歌地图交通层。当我们拖动屏幕或放大/缩小时,我应该继续绘制。为此,我在TouchOverlay
类中使用onZoom()
方法中的相同getGPSPoints
方法。
但是,当我第一次选择该选项并进行第一次放大/缩小操作时,它只是绘制一次。如果我需要绘制剩余部分,则必须按照当前实现再次单击该选项。这项活动如何运作,我应该拥有它?
【活动生命周期(http://developer.android.com/ reference/android/app/Activity.html#ActivityLifecycle) – Lucifer