2010-04-17 63 views
0

在Android中,我有一些代码来检查用户是否已打开GPS,然后启动“设置”以使它们打开,如果它们没有。它看起来像这样:Android:当应用程序重新打开时停止活动?

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(); 
} 

然而,我发现,如果用户打开设置,打开GPS,然后进行使用的应用程序正常,有一个奇怪的问题。通常,当用户重新打开应用程序时,设置位于前面。我如何设置它们,使它们不再出现?

我不知道是否应该使用CLEAR_TOP标志或类似的东西。我已经试过看文档的活动标志,但发现他们有点混乱。有人知道吗?

回答

相关问题