在我的活动中,我正在检查 GPS 和 WIFI 定位服务是否都关闭。
如果两者都关闭,则会触发定位服务的意图。但是,当我按下返回按钮时,我无法返回我的活动,而是返回主屏幕。因此屏幕卡在位置设置页面。
请注意,我正在扩展 FragmentActivity 并使用 SupportMapFragment。
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if (status != ConnectionResult.SUCCESS)
{ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,requestCode);
dialog.show();
} else
{
fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(locationManager != null)
{
gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(gpsIsEnabled==false && networkIsEnabled==false)
{
Log.i("code","both wifi and gps off.");
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 1);
}
else
{
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
location = locationManager.getLastKnownLocation(provider);
if (location != null)
{
onLocationChanged(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, this);
}
}
else
{
Log.i("app","null.");
}