当用户输入错误的密码时(如果不成功),我在 Android 应用程序的登录 Activity 中遇到错误。显示用户输入错误密码(例如)时的错误,但也会显示调试期间的错误。不知道为什么。
错误:
E/WindowManager: android.view.WindowLeaked: Activity de.myfirstapp.app.LoginActivity has leaked window DecorView@a5b0d96[] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:435)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at android.app.Dialog.show(Dialog.java:316)
at de.myfirstapp.app.LoginActivity$1$1$override.onResponse(LoginActivity.java:68)
at de.myfirstapp.app.LoginActivity$1$1$override.access$dispatch(LoginActivity.java)
at de.myfirstapp.app.LoginActivity$1$1.onResponse(LoginActivity.java:0)
at de.myfirstapp.app.LoginActivity$1$1.onResponse(LoginActivity.java:50)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6209)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
我的重要代码:
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
String displayName = jsonResponse.getString("display_name");
Intent intent = new Intent(LoginActivity.this, UserAreaActivity.class);
intent.putExtra("displayName", displayName);
LoginActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Login informations are wrong. Please check email and password")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Webspace is currently not reachable.")
.setNegativeButton("Ok", null)
.create()
.show();
}
}
};
谢谢你帮助我:)
最佳答案
在 Dialog
上调用关闭:
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Login informations are wrong. Please check email and password")
.setNegativeButton("Retry",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//retry or dialog.dismiss();
}
})
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Webspace is currently not reachable.")
.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
})
.create()
.show();
}
关于java - Activity 泄漏了最初添加到此处的窗口(当登录数据错误时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41630880/