我正在使用禁用GPS的AlertDialog,一旦用户启用GPS,我将通过Intent移动到另一个活动。问题是出现AlertDialog,然后移动到下一个活动,然后我可以单击对话框上的任何按钮。 我需要做什么才能让下一个Intent只执行一次我在AlertDialog上执行的操作? 这里是我的代码:Android:警报对话框消失并执行下一个Intent
public void OnClickNearMe(View view) {
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
createGpsDisabledAlert();
}
Location locationResult = null;
MyLocation myLocation = new MyLocation();
boolean locationEnabled = myLocation.getLocation(this, locationResult);
if (locationEnabled == true) {
locationResult = myLocation.getLocationResult();
showResultsScreen(locationResult);
} else
Toast.makeText(this, R.string.noLoc, Toast.LENGTH_LONG).show();
return;
}
private void createGpsDisabledAlert() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS is disabled! Would you like to enable it?")
.setCancelable(false)
.setPositiveButton("Enable GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
showGpsOptions();
}
});
builder.setNegativeButton("Do nothing",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void showGpsOptions() {
Intent gpsOptionsIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gpsOptionsIntent);
}
private void showResultsScreen(Location locationResult) {
Intent resultsIntent = new Intent(this, ResultScreenList.class);
startActivity(resultsIntent);
}
在此先感谢您的答案!
谢谢你,工作。有什么方法可以让用户退出设置页面,而不必按下后退按钮?这是我的初衷。 – Sushma 2011-06-17 14:52:55
想到这些并不太明显。你也许可以弹出一杯祝酒词,指导用户在完成后向他们反馈,但除此之外,我对此没有任何明智的想法。 – kabuko 2011-06-17 18:09:06