0
我已經制作了這段代碼。只要在對話框中按下「ok」按鈕,應用程序就會崩潰並出現上述異常。我無法弄清楚爲什麼,有什麼幫助?我遵循Android文檔中的這些說明。Android「android.view.WindowLeaked:」例外
package com.grawl.faqplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class FAQPlusActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set up buttons
Button buttonExit = (Button) findViewById(R.id.button_exit);
Button buttonAbout = (Button) findViewById(R.id.button_about);
// Set up AlertDialog for buttonAbout
String aboutMessage = (String) getString(R.string.dialog_about);
AlertDialog.Builder builderAbout = new AlertDialog.Builder(this);
builderAbout.setMessage(aboutMessage);
builderAbout.setCancelable(false);
builderAbout.setNeutralButton("OK!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
final AlertDialog alertAbout = builderAbout.create();
// Show about dialog
buttonAbout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
alertAbout.show();
}
});
// Exit app
buttonExit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
}
http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-替換
固定它最初添加 – 2012-01-14 01:30:32