我知道关于这个话题有很多答案......但我无法找到解决我的问题的方法。它很简单,一个活动:
public class DialogsActivity extends Activity {
Bundle bundle=new Bundle();
String token;
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mostrarDialogo();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialogsactivitylayout);
bundle=getIntent().getExtras();
token=bundle.getString("token");
token=token.replaceAll("\\s+","");
Log.i("Parse", "Token: "+token);
}
private void mostrarDialogo() {
if(token.equals("nologin")){
AlertDialog.Builder nologin = new AlertDialog.Builder(DialogsActivity.this);
nologin.setTitle(R.string.loginstring);
nologin.setMessage(R.string.nologin);
nologin.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
finish();
return;
}
});
nologin.show();
}else if(token.equals("nocon")){
AlertDialog.Builder nocon = new AlertDialog.Builder(DialogsActivity.this);
nocon.setTitle(R.string.loginstring);
nocon.setMessage(R.string.timeout);
nocon.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
finish();
return;
}
});
nocon.show();
}else if(token.equals("oklogin")){
AlertDialog.Builder start=new AlertDialog.Builder(DialogsActivity.this);
start.setTitle(R.string.warn);
start.setMessage(R.string.service);
start.setNegativeButton(R.string.accept,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
return;
}
});
//finish();
start.show();
}else if(token!="nocon" && token!="nologin" && token!="oklogin"){
AlertDialog.Builder error=new AlertDialog.Builder(DialogsActivity.this);
error.setTitle(R.string.unknownerror);
error.setMessage(R.string.unkerrortext);
error.setPositiveButton(R.string.accept,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
return;
}
});
error.show();
}
}
}
当活动运行时,堆栈跟踪:
05-21 11:46:25.140: E/WindowManager(15737): Activity com.publidirecta.vinceriazafata.DialogsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405aeb60 that was originally added here
05-21 11:46:25.140: E/WindowManager(15737): android.view.WindowLeaked: Activity com.publidirecta.vinceriazafata.DialogsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405aeb60 that was originally added here
05-21 11:46:25.140: E/WindowManager(15737): at android.view.ViewRoot.<init>(ViewRoot.java:263)
05-21 11:46:25.140: E/WindowManager(15737): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:171)
05-21 11:46:25.140: E/WindowManager(15737): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
05-21 11:46:25.140: E/WindowManager(15737): at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.Dialog.show(Dialog.java:241)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.AlertDialog$Builder.show(AlertDialog.java:809)
05-21 11:46:25.140: E/WindowManager(15737): at com.publidirecta.vinceriazafata.DialogsActivity.mostrarDialogo(DialogsActivity.java:88)
05-21 11:46:25.140: E/WindowManager(15737): at com.publidirecta.vinceriazafata.DialogsActivity.onResume(DialogsActivity.java:20)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.Activity.performResume(Activity.java:3832)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-21 11:46:25.140: E/WindowManager(15737): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 11:46:25.140: E/WindowManager(15737): at android.os.Looper.loop(Looper.java:130)
05-21 11:46:25.140: E/WindowManager(15737): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-21 11:46:25.140: E/WindowManager(15737): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 11:46:25.140: E/WindowManager(15737): at java.lang.reflect.Method.invoke(Method.java:507)
05-21 11:46:25.140: E/WindowManager(15737): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-21 11:46:25.140: E/WindowManager(15737): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-21 11:46:25.140: E/WindowManager(15737): at dalvik.system.NativeStart.main(Native Method)
错误总是在 .show() 方法上跳转,具体取决于它在一个 if 或另一个中输入的令牌变量的值。而且,如您所见,对话框总是被关闭。有什么帮助吗?谢谢!