希望這有助於你
public class MyLocationListener extends LocationListener{
public interface MyLocCallbacks{
onLocFound(double lat, double lng);
}
private MyLocCallbacks mCallbacks;
public MyLocationListener(MyLocCallbacks callback){
this.mCallbacks = callback;
//Make sure to start the LocationSerivce here
}
public void onLocationChanged(final Location loc) {
this.mCallbacks.onLocFound(log.getLatitude(), loc.getLongitude())
}
}
MainActivity
public class MainActivity implements MyLocCallbacks{
private MyLocationListener mLocListener;
onCreate(S...){
mLocListener = new MyLocationListener(this); //this for the interface
}
//This one is called by your Location Listener
@Override
onLocFound(double lat, double lng){
startAnimation();
}
private void startAnimation(){
//do here your startAnimation,
//before you could show a simple loading screen
}
}
只是實現自己的回調/接口(例如,onLocationFound(雙緯度,雙LNG)和火在你的活動這個活動?你知道我的意思嗎? –
但是我可以從locationManager類訪問它嗎?ui線程如何等待它呢? –
只要給我5分鐘我會給你寫一個例子 –