안드로이드에서 작동하는 프로그램이 너무 명확하지 않습니다. 지난 두 달 동안 Android에서 작업하기 시작했으며 자바 초보자입니다. 그래서 나는 개발하고 배우기 위해 최선을 다하고 있습니다. 다음은 구현 한 코드 조각이며 내 요구 사항에 따라 작동 방식이 명확하지 않습니다.활동의 수명주기 란 무엇입니까?
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()
으로 메소드를 만들었으므로 획득 한 점을 맵에 표시하고 싶습니다. 내 의도는 구글 맵 트래픽 레이어와 같다. 화면을 드래그하거나 확대/축소 할 때 계속해서 그려야합니다. 이를 위해 클래스의 onZoom()
메서드 내에서 동일한 getGPSPoints
메서드를 사용하고 있습니다.
처음 옵션을 선택하고 첫 번째 확대/축소 작업을 수행 할 때 한 번 그립니다. 나머지를 그릴 필요가 있으면 현재 구현에 따라 옵션을 다시 클릭해야합니다. 이 활동은 어떻게 작동합니까?
[활동 수명주기 (http://developer.android.com/ reference/android/app/Activity.html # ActivityLifecycle) – Lucifer