1

我有一个 AlertDialog,我希望在单击“确定”后重新加载主活动。问题是在我单击“确定”后,我的活动返回到主屏幕。

JAVA代码:

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(
        "This application needs GPS satellite or Wireless Networks localization enabled" 
        + "\n" + "Do you want to enable it?")
        .setCancelable(true)
        .setPositiveButton("Yes",
    new DialogInterface.OnClickListener() {
        public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
            startActivity(new Intent(
            Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            finish();
            startActivity(getIntent());
        }

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

}

帮助将不胜感激。

4

2 回答 2

2

更改此代码

new DialogInterface.OnClickListener() {
    public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
        startActivity(new Intent(
        Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        finish();
        startActivity(getIntent());
    }  

new DialogInterface.OnClickListener() {
    public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
        startActivityForResult(new Intent(
        Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
    }
于 2013-03-21T07:10:29.027 回答
0

再次调用 onCreate 方法。但是将 null 作为参数传递。

onCreate(null);
于 2013-03-21T07:05:42.797 回答