How To Get Location Using AsyncTask

前端 未结 4 498
栀梦
栀梦 2020-12-05 09:08

I am pulling my hair out with trying to find a good solution to this problem. I made my app so it finds my location. It seems overly complicated but easy enough. However fol

4条回答
  •  广开言路
    2020-12-05 09:36

    First to fix your compilation problem, move

    LocationManager locationManager = (LocationManager)params[0].getSystemService(Context.LOCATION_SERVICE);        
    

    So that it's a private member variable of the class.

    LocationManager does not have to be in an AsyncTask. It does not tie up the UI, all updates are already asynchronous. This will just add needless complication to your project.

    You probably only need to move useLocation into onLockationChanged.

提交回复
热议问题