0

在我的登录活动中,我检查用户是否已激活/打开他们的 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();
  }
}
4

2 回答 2

0

你是在你的或finish();之后的某个地方打电话吗? 查看Activity 生命周期,您会看到在启动 Settings-Intent 时调用它。startActivity()onPause()
onPause()

于 2013-01-14T15:58:14.143 回答
0

整理出了问题。在清单文件中,活动的标签noHistory="true"(据我所知)不会将其添加到堆栈中。因此不能“回到”活动。

于 2013-01-17T10:51:22.427 回答