안녕하세요? 저는 초보 개발자 야마돌기 라고 합니다 ㅠ


제가 어플을 개발중인 것이 있는데요


예를들면 .. 백그라운드에서 gps 주소값을 계속적으로 수집을 하고 있다가

제가 특정한 이벤트를 주었을 때. 그 주소값으로 문자를 보낸다던지 하는 어플리케이션을 만들고 있습니다.


어플을 실행 시키면 Intentservice가 시작되고, 그 안에서 gps값을 받게 되는데요 .

이 인텐트 서비스는 특정한 이벤트. 예를들면 센서값을 4번을 주어야지만 문자가 보내지도록 하게 만들고 싶은건데

3번까지 센서값을 받고 3초가 지나면 서비스는 죽었다가 다시 살아나게 됩니다. 

하지만 GPS는 꺼지지 않기 때문에 중복으로 처리 되고.

제 생각에는 이 때문에 onLocationChanged가 중복처리되어서 제대로 된 주소값을 받아오지 못하는 것 같아요.


하지만 서비스가 죽을때마다 gps를 죽인다면, 센서값을 3번 주고나서 서비스가 죽어서 다시 살아나고

살아나자마자 이벤트를 준다면 gps가 차마 위치를 받기도 전에 문자가 가버리게 되어서그런지 아무것도 써있지 않은 상태로 갑니다.


소스첨부 하겠습니다 ㅠㅠ 저도 제 나름대로 일주일을 고민하고 했는데 도저히 모르곘어요

따로 엑티비티를 만들어서 해 보기도 하고 했는데도..

고수님들 한번 부탁드리겠습니다.



public class Bservice extends IntentService implements LocationListener

{

...

           locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

           locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);


이 안에서 0.5초 간격으로 

GetLocations();

...

}


public void onLocationChanged(Location location) {

        Log.e("LOLLOL", "location changed"+latPoint+lngPoint);

        myLocation = location;

     //GetLocations();

    }


public void GetLocations() {


    Geocoder geoCoder = new Geocoder(this);

   

    StringBuffer juso = new StringBuffer();


    if (myLocation != null) {

    latPoint = myLocation.getLatitude();

    lngPoint = myLocation.getLongitude();

    speed = (float)(myLocation.getSpeed() * 3.6);


    try {


    List<Address> addresses;

    addresses = geoCoder.getFromLocation(latPoint, lngPoint, 1);

   

   

    for(Address addr: addresses){

    int index = addr.getMaxAddressLineIndex();

    for(int i=0;i<=index;i++){

    juso.append(addr.getAddressLine(i));

    juso.append(" ");

    }

    //juso.append("\n");

    }

   

    } catch (IOException e) {

    e.printStackTrace();

    }

   

    if(String.valueOf(juso) == null)

    {

    /*

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

            SharedPreferences.Editor editor = pref.edit();

                editor.putString("lodata","faled get gps"); 

                editor.commit();

                */

    }

   

    else 

    {

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

            SharedPreferences.Editor editor = pref.edit();

                editor.putString("lodata",String.valueOf(juso));

                editor.commit();

    }

   

    }

    else if(myLocation == null)

    {

    juso.append("I don't know");

    }


    }