GPS not working in Async Task

前端 未结 3 424
北海茫月
北海茫月 2021-01-25 03:05

I have implemented a simple GPS program that fetches the co-ordinates and displays them on the screen. When I tried to improve on this design and implement an async task, the GP

3条回答
  •  离开以前
    2021-01-25 03:47

    If you want a dirty and not much sensual way:

    mLocationManager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
    Looper.prepare();
    Looper.loop();
    if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){    
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MINIMUM_TIME, GPS_MINIMUM_DISTANCE, MyFragment.this);
    }
    Looper.myLooper().quit();
    

    Basically, it makes the current thread, a main thread on which messages will be executed, after shortly you give up this thread being a main thread. I'm not sure of the consequences of this.

提交回复
热议问题