2013-03-21 41 views
1

我有一個AlertDialog,並且在單擊「確定」後我想要重新加載主活動。問題出在點擊確定後,我的活動返回到主屏幕。如何在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(); 

} 

幫助,將不勝感激。

+1

我認爲你需要刪除完成()調用。 – 2013-03-21 07:10:34

回答

0

再次調用onCreate方法。但是將null作爲參數傳遞。

onCreate(null); 
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); 
    } 
相關問題