简体   繁体   中英

error dialog.show(); Alert dialog

I have an AlertDialog it works fine but I noticed that it marks me an error in the line where I put dialog.show (); I do not know how I could solve it.

IngresarAdmin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final AlertDialog.Builder mBuilder=new AlertDialog.Builder(InicioSesion_Principal.this);
            View Mview= getLayoutInflater().inflate(R.layout.zona_restrigida,null);
            final  EditText claveAdmin=(EditText)Mview.findViewById(R.id.Clave_proveedor);
            Button EntrarClaveAdmin=(Button)Mview.findViewById(R.id.Ingresar_clave_proovedor);
            EntrarClaveAdmin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!claveAdmin.getText().toString().isEmpty()){
                        Intent intent=new Intent(getApplicationContext(), menu_administrador.class);
                        startActivity(intent);
                        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                        finish();
                    }
                    else {
                        Toast.makeText(InicioSesion_Principal.this,"Clave incorrecta",Toast.LENGTH_SHORT).show();
                    }
                }
            });
            mBuilder.setView(Mview);
            AlertDialog dialog=mBuilder.create();
            dialog.show();
        }
    });

This is the error that shows me in the dialog.show(); It does not close the application at any time, but how can I fix it?

android.view.WindowLeaked: Activity com.tienda.app.aplicaciontienda.Iniciar_Sesion_3.InicioSesion_Principal has leaked window com.android.internal.policy.PhoneWindow$DecorView{245d004 V.E...... R......D 0,0-683,503} that was originally added here
                                                                              at android.view.ViewRootImpl.<init>(ViewRootImpl.java:375)
                                                                              at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
                                                                              at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
                                                                              at android.app.Dialog.show(Dialog.java:319)
                                                                              at com.tienda.app.aplicaciontienda.Iniciar_Sesion_3.InicioSesion_Principal$3.onClick(InicioSesion_Principal.java:119)
                                                                              at android.view.View.performClick(View.java:5201)
                                                                              at android.view.View$PerformClick.run(View.java:21163)
                                                                              at android.os.Handler.handleCallback(Handler.java:746)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

try using dialog.create().show(); I had the same problem.

You need to call .dismiss();

if(dialog != null)
    dialog.dismiss();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM