2013-08-07 4 views
0

GPS 실행을 원할 때 데이터베이스를 확인하는 코드가 있습니다. 이 메소드를 실행하려면 Intentservice를 사용하고 있습니다. 나는 Looper 구현을 시도했지만 그 코드를 다시 실행하지 않는 코드로 끝난다. Looper가 없으면 Looper.prepare()를 호출하지 않은 스레드에서 핸들러를 생성 할 수 없다는 Looper 에러가 발생합니다.intentservice에서 위치 업데이트 토글

Timer timer = new Timer(); 
TimerTask gpsTask = new TimerTask() { 
    @Override 
    public void run() { 
     // TODO Auto-generated method stub 
     gpsPlotter(); 
    } 
}; 

// schedule the task to run starting now and then every hour... 
timer.schedule(gpsTask, 0, 200); 


private void gpsPlotter(){ 
     // TODO Auto-generated method stub 
      try{ 
       BeaconHandler dbg = new BeaconHandler(Ping.this); 
       List<Beacon> beacons = dbg.getAllBeacons(); 
       int activecheck = 0; 
       for(Beacon bn : beacons){ 
        activecheck = activecheck + bn.getStatus(); 
       } 
       //db.close(); 
       if(activecheck > 0 && updateset == 0){ 
        pinger.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, reciever); 
        updateset = 1; 
        Log.d("GPS RESET", "Listener Set"); 
       } 
       else if(activecheck == 0 && updateset == 1){ 
        pinger.removeUpdates(reciever); 
        updateset = 0; 
        Log.d("GPS RESET", "Listener Removed"); 
       } 
       else{ 
        Log.d("GPS RESET", "No Modifications"); 
       } 
      } 
      catch(Exception e){ 
       Log.e("GPS RESET ERROR", e.getMessage(), e); 
      } 
     } 

답변

0

내 문제가 발견되었습니다. 요청한 위치 업데이트를 시작할 때 그렇게 등록해야했습니다.

pinger.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, reciever, getMainLooper());