【问题标题】:Android - Navigate back to app from System SettingsAndroid - 从系统设置导航回应用程序
【发布时间】:2013-01-14 15:52:25
【问题描述】:

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

【问题讨论】:

  • 你能把整个代码显示给你的AlertDialog吗?我怀疑你在某处打电话给finish()。
  • 设置应用程序的行为可能因设备制造商而异,因为他们比其他应用程序更倾向于修补此应用程序。虽然它通常应该返回给您(AFAIK),但这不是必需的。尽管正如 iagreen 指出的那样,您开始活动的方式可能会在该领域造成高于平均水平的困难。

标签: android navigation settings system back


【解决方案1】:

您是在startActivity() 之后的某个地方还是在onPause() 中调用finish();?
查看Activity Life Cycle 你会看到onPause() 在你启动Settings-Intent 时被调用。

【讨论】:

  • 我在编辑中包含了我的 onPause() 和 onResume() 方法。
  • 代码看起来没问题。在模拟器上运行您的应用程序,以确保它不是特定于设备的问题。
【解决方案2】:

解决了问题。 在清单文件中,活动具有标签noHistory="true"(据我所知)不会将其添加到堆栈中。 因此无法“返回”活动。

【讨论】:

    猜你喜欢
    • 2018-05-06
    • 2019-07-29
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    相关资源
    最近更新 更多