【发布时间】: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