1

I'm getting a error during my login activity in my android app when the user typed in a wrong passwort (if success isn't true). The error when a user typed in a wrong password (for example) is shown but also a error during the debugging is shown. Don't know why.

Error:

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)

My code which is important:

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

Thank you for helping me :)

ItsOdi1
  • 219
  • 3
  • 22

2 Answers2

1

Call dismiss on 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();
     }
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
0

just need to dismiss the dialog before activity/fragment got destroyed... so make sure of this or if you want to dismiss the activity as well at same time then you need to use it through

    @Override
public void onBackPressed() {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
           // MainActivity.this.finish();
            //or
//MainActivity.this.getSupportFragmentManager().popBackStack();
        }
    }, 500);
}
Deepak sharma
  • 687
  • 7
  • 8