[英]Android: stop activity appearing when an app is reopened?
In Android, I have some code to check whether the user has GPS switched on, and launch the Settings for them to turn it on if they don't. 在Android中,我有一些代码可以检查用户是否已打开GPS,并启动设置以供用户打开(如果未打开)。 It looks like this:
看起来像这样:
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setMessage(
"Your GPS seems to be disabled - you need it to get a location fix. Turn it on now?")
.setCancelable(false).setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(
@SuppressWarnings("unused") final DialogInterface dialog,
@SuppressWarnings("unused") final int id) {
Intent j = new Intent();
j.setAction("android.settings.LOCATION_SOURCE_SETTINGS");
startActivity(j);
}
}).setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,
@SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
However, I'm finding that if the user opens the Settings, turns GPS on, then carries on using the app as normal, there is an odd problem. 但是,我发现,如果用户打开“设置”,打开GPS,然后像往常一样继续使用该应用程序,则会出现一个奇怪的问题。 Often, when the user reopens the app, the Settings are at the front.
通常,当用户重新打开应用程序时,设置位于最前面。 How can I set them so they don't keep reappearing?
我该如何设置它们以使其不重新出现?
I wonder if I should be using the CLEAR_TOP flag or something similar... I've tried looking at the docs for the Activity flags but find them a bit confusing. 我想知道我是否应该使用CLEAR_TOP标志或类似的东西...我尝试查看文档中的Activity标志,但发现它们有些混乱。 Anyone know?
有人知道吗
听起来您想在活动中使用noHistory属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.