마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 시간갱신 주기

0 추천
gps 위도, 경도를 받아서 데이터베이스에 저장해주는 소스인데요.
빨간색으로 된 줄 보시면 5초마다 갱신을 해주었는데 log가 찍힌 시간을 보니 45초마다 갱신이 되던데요..
왜그런가요?? 
 
 
 
public class GPSservice extends Activity {
 
static JSONParser jParser = new JSONParser();
 
private static String ulati,ulongi;
 
private static String url_register = "http:/"IP"/gps.php";
//private static final String TAG_LOGIN_SUCCESS = "success";
private List<NameValuePair> params;
//================================================
 
//=============================================
 
    TextView statusText, result;
    //위치정보를 공급하는 근원
    String locationProvider;
    //위치 정보 매니져 객체
    LocationManager locationManager;
//    int count; //위치 정보 갱신 횟수를 세기 위한 변수
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);
            
        
        //필요한 객체의 참조값 얻어오기
        statusText = (TextView)findViewById(R.id.status);
        result = (TextView)findViewById(R.id.result);
        //위치 정보 매니져 객체 얻어오기
        locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        //위치정보 공급자 얻어오기
        locationProvider = locationManager.getBestProvider(new Criteria(), true);
//        Toast.makeText(this, "위치정보 공급자:"+locationProvider, 0).show();
        //가장 최근의 Location 객체 얻어오기
        Location location = locationManager.getLastKnownLocation(locationProvider);
      
    }
    //==================================================
  
    
    //====================================================================
    
    
    @Override
    protected void onResume() {
     super.onResume();
     //(위치 정보 공급자, 갱신주기, 갱신거리, 리스너)
     locationManager.requestLocationUpdates(locationProvider, 5000, 0, listener);
     
    }
    @Override
    protected void onPause() {
        super.onPause();
        locationManager.removeUpdates(listener);
    }
    //locationListener객체 만들기
    LocationListener listener = new LocationListener() {
  //상태가 바뀌었을 때
  public void onStatusChanged(String provider, int status, Bundle extras) {
   String msg = "";
   switch(status){
   case LocationProvider.OUT_OF_SERVICE :
    msg = "서비스 지역이 아닙니다.";
    break;
   case LocationProvider.TEMPORARILY_UNAVAILABLE :
    msg = "일시적으로 위치 정보를 사용할 수 없습니다.";
    break;
   case LocationProvider.AVAILABLE :
    msg = "서비스 가능 지역입니다.";
    break;
   }
   statusText.setText(msg);
  }
  //공급자가 공급 가능하게 되었을 때
  public void onProviderEnabled(String provider) {
   statusText.setText("현재 상태: 위치정보 이용가능");
  }
  //공급자가 공급 못하게 되었을 때
  public void onProviderDisabled(String provider) {
   statusText.setText("현재 상태: 위치정보 이용불가");
  }
  //위치 정보가 바뀌엇을때 호출되는 메소드
  public void onLocationChanged(Location location) {
 //  count++;
  
 
 double mylati= location.getLatitude();
 String lati = Double.toString(mylati);
 double mylong= location.getLongitude();
 String longi = Double.toString(mylong);
 
 
//   StringBuffer buffer = new StringBuffer();
//   buffer.append("수신횟수:"+count+"\r\n");
//   buffer.append("위도:"+location.getLatitude()+"\r\n");
//   buffer.append("위도:"+location.getLongitude()+"\r\n");
   //위치정보 출력하기
  // result.setText(buffer.toString());
   
   AlertDialog.Builder builder = new AlertDialog.Builder(
GPSservice.this);
    params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("id", "moon"));
    Log.e("a:","moon");
    Log.e("b:",lati);
    Log.e("c:",longi);
    params.add(new BasicNameValuePair("latitude", lati));
params.add(new BasicNameValuePair("longitude", longi));
 
////////////// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_register, "GET", params);
 
  }
 };    
}
생포카칩 (120 포인트) 님이 2013년 5월 28일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...