我不清楚如何在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