Reputation: 171
can anybody suggest me what should i implement, to show a wait message untill LocationListener.onLocationChanged get called ?
I tried using a dialog without title, but the problem is-
1. If i make it setCancelable(false)
, than user is unable even to press back button.
2. If i make setCancelable(true)
, then it goes out before onLocationChanged().
below is my code
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Please Wait for GPS Signals...").setCancelable(false);
mLocationWaitDialog = builder.create();
mLocationWaitDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams layoutParam = mLocationWaitDialog.getWindow().getAttributes();
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
layoutParam.y = -height / 2; // y position
mLocationWaitDialog.show();
Upvotes: 0
Views: 54
Reputation: 6469
I have this:
In the OnCreate method:
if (lastKnownLocation == null) {
Log.i("Location", "lastKnownLocation es null");
dialog = ProgressDialog.show(this, "Buscando...", "");
}
dialog is declared above, its a ProgressDialog.
Then, in a Handler:
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.i("Location", "Mensaje recibido2");
if(dialog!=null){
dialog.dismiss();
}
LatLng gpsrc = new LatLng(msg.getData().getDouble("lat"),
msg.getData().getDouble("lon"));
continuar(gpsrc);
}
};
My onLocationChanged method:
public void onLocationChanged(Location location) {
double nuevalat=location.getLatitude();
double nuevalon=location.getLongitude();
origen=new LatLng(nuevalat, nuevalon);
Bundle bundle=new Bundle();
bundle.putDouble("lat", origen.latitude);
bundle.putDouble("lon", origen.longitude);
Message mescoords = new Message();
mescoords.setData(bundle);
try {
handler.sendMessage(mescoords);
} catch (Exception e) {
e.printStackTrace();
}
}
This way, when the onLocationChanged method is called, a message is sent, which dismiss the ProgressDialog. Try if with ProgressDialog the user can back, Im not sure.
Upvotes: 1
Reputation: 1060
I would try setting a timeout timer that sets cancelable to true after a certain amount of time. That would solve your problem of having it go away right away, while also not locking the user in a loop if no GPS can be found.
Upvotes: 0
Reputation: 916
ProgressDialog pd = new ProgressDialog(activity);
pd.setMessage("Loading.. Please wait");
pd.show();
inside onLocationChanged() stop it
pd.dismiss();
Upvotes: 0