在我的登录活动中,我检查用户是否已激活/打开他们的 GPS。如果没有,我只是显示一个AlertDialog要求用户打开 GPS 的信息。
从AlertDialog我启动/启动一个 Intent 如下:                     
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingsIntent);
当从系统设置中按下返回按钮时,用户返回到手机的主屏幕......即“关闭应用程序”。
我试过onActivityResult但没有用。此外,我已经阅读了其他用户遇到的类似问题,但由于大多数答案与使用onActivityResult.
有人可以对此事有所了解吗?
编辑:
这是完整的代码AlertDialog:
builder = new AlertDialog.Builder(this);
builder.setTitle("GPS Not Found");
builder.setMessage("Want To Enable?");
//Dialog - Yes option
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialogInterface, int i)
{
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(settingsIntent,1);
}
});
//Dialog - No option                
builder.setNegativeButton("No", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialogInterface, int i)
{
}
});
//Show he dialog
builder.create().show();
编辑:
这里是OnPause()和OnResume()方法。我只是检查提供程序是否仍然处于活动状态并且与locationManager. 当我从“设置”返回时,“TEST 1”和“TEST 2”都不会打印。
@Override
protected void onResume()
{
  Log.i(ERRORTAG, "TEST 1");
  super.onResume();
  if(provider != null)
  {
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, refreshTime, refreshDistance, this);
    gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  }
}
@Override
protected void onPause()
{
  Log.i(ERRORTAG, "TEST 2");
  super.onPause();
  if(locationManager != null)
  {
    locationManager.removeUpdates((LocationListener) this);
    gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  }
  if(loginDialog != null)
  {
    loginDialog.dismiss();
  }
}