2013-04-19 1 views
0

제대로 작동하려면 일정 기간 동안 코드를 유지해야하는 코드 조각이 있습니다. 그러나 35 초가 시작될 때 코드가 멈추지 만 원하는대로 작동하지 않습니다. IE는 내가 원하는 출력을 얻지 못한다."일시 중지"앱이 작동하지만 원하는 방식으로 작동하지 않습니다.

여기 제가 작업하고있는 코드가 있습니다.

 LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    LocationListener mlocListener = new MyLocationListener(); 
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, 
      mlocListener); 
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
      1000L, 1.0f, (LocationListener) this); 
    boolean isGPS = locationManager 
      .isProviderEnabled(LocationManager.GPS_PROVIDER); 

    // Methods to make the code wait 35 seconds 
    int time = 35000; 
    try { 
     Thread.sleep(time); 
    } catch (InterruptedException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    Intent WriteOut = new Intent(context, WriteOut.class); 
    WriteOut.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(WriteOut); 

나는 시스템이/발사 장치의 GPS 신호를 획득 할 수있는 기회를 한 후 현재의 GPS 좌표를 출력하려합니다.

이 문제를 해결하는 방법에 대한 팁은 내가 분명히 잘못된 일을하고 있기 때문에 훌륭합니다.

+0

이'Activity' 내부 코드가 도움이되는지 알려주세요? – codeMagic

+0

아니요. 그것의 외부/클래스에 표시됩니다. 그것이 당신이 찾고있는 대답이라면. @codeMagic – CodeMonkeyAlx

+0

그게 도움이되고 싶다. – codeMagic

답변

0

코드를 실행하기 전에 서비스가 시작되지 않으면 코드를 실행 한 후 Threadsleep()을 호출하는 것이 도움이되지 않습니다. 대기 시간을 늘리고 변경할 필요가있는 값을 확인하면서 일정 시간 동안 잠자기 상태로 두십시오. 나는 GPS를 엉망으로 만들지 않아서 당신이 무엇을 확인해야하는지 정확히 알지 못하지만 당신이 확신합니다.

LocationListener mlocListener = new MyLocationListener(); 

// Methods to make the code wait 35 seconds 
int time = 35000; 
int curTime = 0; 
while (curTime<time && aCoordingateVariable = aDefaultValue) // I don't mess with GPS so I don't know what you need there but that should give you the idea 
try { 
     Thread.sleep(100); 
     LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

     mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, 
     mlocListener); 
     LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
     1000L, 1.0f, (LocationListener) this); 
     boolean isGPS = locationManager 
     .isProviderEnabled(LocationManager.GPS_PROVIDER);enter code here 
} catch (InterruptedException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

는이

+0

몇 가지 이상한 이유로 그것은 내가 필요로하는 방식으로 여전히 작동하지 않습니다. 나는 당신이 뭔가를 생각합니다 ... 그 여전히 "0.0"오류를 크랭크 아웃. – CodeMonkeyAlx

관련 문제