我想根据用户当前的位置向用户提供一些优惠。
这意味着ui应该等待(不要被阻止,而是等待动画) - 所以我想使用位置监听器和asyncTask。
但是侦听器签名返回void
public class MyLocationListener implements LocationListener {
public void onLocationChanged(final Location loc) {
并且asynTask在这里没有帮助(因为它是我活动中的一个分类课程)
你会怎么建议这样做?
答案 0 :(得分:0)
希望这有助于你
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
}
}